package billing import ( "context" "errors" "strings" "github.com/jackc/pgx/v5" ) // SuperAdminPlanName is an internal assignable plan: every dashboard feature ON, // unlimited SKUs, and the Enterprise-sized credit grant. Not on the public ladder. const SuperAdminPlanName = "Super Admin" // IsSuperAdminPlan reports the fully unlocked internal plan (assign via admin billing). func IsSuperAdminPlan(name string) bool { return strings.EqualFold(strings.TrimSpace(name), SuperAdminPlanName) } // EnsureSuperAdminPlan upserts the Super Admin plan row (is_custom=true → enable-all features). func (s *Service) EnsureSuperAdminPlan(ctx context.Context) error { if s == nil || s.Pool == nil { return errors.New("billing service unavailable") } desc := "Internal unlock — every feature enabled, unlimited SKUs, large AI grant (not sold publicly)" var id int64 err := s.Pool.QueryRow(ctx, ` SELECT id FROM plans WHERE lower(name) = lower($1) ORDER BY id LIMIT 1`, SuperAdminPlanName).Scan(&id) if errors.Is(err, pgx.ErrNoRows) { _, err = s.Pool.Exec(ctx, ` INSERT INTO plans (name, description, monthly_credits, yearly_credits, max_products, is_custom, term) VALUES ($1, $2, $3, NULL, NULL, true, 'monthly')`, SuperAdminPlanName, desc, EnterpriseUnlimitedCredits) return err } if err != nil { return err } _, err = s.Pool.Exec(ctx, ` UPDATE plans SET description = $2, monthly_credits = $3, max_products = NULL, is_custom = true, term = 'monthly', updated_at = now() WHERE id = $1`, id, desc, EnterpriseUnlimitedCredits) return err }