package scopeTypes

// Scope represents a limit on the access that a grant provides.
type Scope struct {
	ID          string
	Name        string
	Description string
}

func ApplyChange(change ScopeChange, scope Scope) Scope {
	changed := scope
	if change.Name != nil {
		changed.Name = *change.Name
	}
	if change.Description != nil {
		changed.Description = *change.Description
	}
	return changed
}

type Scopes []Scope

func (s Scopes) Len() int {
	return len(s)
}

func (s Scopes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s Scopes) Less(i, j int) bool {
	return s[i].ID < s[j].ID
}

func (s Scopes) Strings() []string {
	res := make([]string, len(s))
	for pos, scope := range s {
		res[pos] = scope.ID
	}
	return res
}

// ScopeChange represents a change to a Scope.
type ScopeChange struct {
	ScopeID     string
	Name        *string
	Description *string
}

func (s ScopeChange) Empty() bool {
	return s.Name == nil && s.Description == nil
}
