/**
 * Tier configuration for SentryAgent.ai AgentIdP.
 * TIER_CONFIG is the single source of truth for all per-tier limits.
 * Never duplicate these values — always import from here.
 */

/**
 * Per-tier limit definitions.
 * `Infinity` signals no enforcement for enterprise tenants.
 */
export const TIER_CONFIG = {
  free: {
    /** Maximum number of non-decommissioned agents allowed per org. */
    maxAgents: 10,
    /** Maximum number of API calls allowed per calendar day (UTC). */
    maxCallsPerDay: 1_000,
    /** Maximum number of token issuances allowed per calendar day (UTC). */
    maxTokensPerDay: 1_000,
  },
  pro: {
    maxAgents: 100,
    maxCallsPerDay: 50_000,
    maxTokensPerDay: 50_000,
  },
  enterprise: {
    maxAgents: Infinity,
    maxCallsPerDay: Infinity,
    maxTokensPerDay: Infinity,
  },
} as const;

/** Union type of valid tier names derived from TIER_CONFIG keys. */
export type TierName = keyof typeof TIER_CONFIG;

/**
 * Ordered tier rank used to validate upgrade direction.
 * Higher index = higher tier.
 */
export const TIER_RANK: Record<TierName, number> = {
  free: 0,
  pro: 1,
  enterprise: 2,
} as const;

/**
 * Returns true when the supplied string is a valid TierName.
 *
 * @param value - The string to test.
 * @returns Type predicate narrowing value to TierName.
 */
export function isTierName(value: string): value is TierName {
  return value in TIER_CONFIG;
}
