package license

// Plan is the contents of a tier at issue time.
//
// This table is the seed. Once the admin service exists (spec 3) it owns the
// authoritative copy in its `plans` collection, and every issued licence
// snapshots the plan it was cut from — so editing a plan never rewrites an
// existing licence, the same rule as workflow_runs.steps_snapshot.
//
// lkctl uses this table to issue by hand until then.
type Plan struct {
	Tier       string
	Name       string
	Deployment string
	Limits     Limits
	Features   []string
}

var plans = map[string]Plan{
	TierFree: {
		Tier:       TierFree,
		Name:       "Free",
		Deployment: DeploymentCloud, // cloud only, by construction
		Limits:     Limits{MaxServers: 3, MaxSecretGroups: 1, MaxChannels: 1},
		Features:   nil,
	},
	TierProfessional: {
		Tier:       TierProfessional,
		Name:       "Professional",
		Deployment: DeploymentCloud,
		Limits:     Limits{MaxServers: Unlimited, MaxSecretGroups: Unlimited, MaxChannels: Unlimited},
		Features:   []string{FeatureConsole, FeatureOIDC},
	},
	TierSelfHosted: {
		Tier:       TierSelfHosted,
		Name:       "Self Hosted",
		Deployment: DeploymentSelfHosted,
		Limits:     Limits{MaxServers: Unlimited, MaxSecretGroups: Unlimited, MaxChannels: Unlimited},
		Features:   []string{FeatureConsole, FeatureOIDC},
	},
}

// PlanFor returns the seed plan for a tier.
func PlanFor(tier string) (Plan, bool) {
	p, ok := plans[tier]
	return p, ok
}
