export type AccessLevel = 'full' | 'limited' | 'read_only' | 'none'

export const SUBSCRIPTION_POLICY = {
  trial: {
    durationDays: 30,
    requiresPaymentMethod: false, // set true when payment capture is mandatory
    oneTrialPerCompany: true,
  },
  payment: {
    paymentPendingTimeoutDays: 7,
    retryScheduleDays: [0, 3, 6, 10, 14],
    maxRetryAttempts: 5,
  },
  pastDue: {
    timeoutDays: 7,
  },
  suspension: {
    cancelAfterDays: 16,
  },
  notifications: {
    trialEndingDaysBefore: [7, 3, 1],
    paymentFailureDaysAfter: [0, 3, 6],
    pastDueDaysAfter: [7],
    suspensionDaysAfter: [14],
    cancellationDaysAfter: [30],
  },
} as const

export const ACCESS_MAP: Record<string, AccessLevel> = {
  TRIALING:        'full',
  ACTIVE:          'full',
  PAYMENT_PENDING: 'full',
  UNPAID:          'full',
  PAST_DUE:        'limited',
  SUSPENDED:       'read_only',
  CANCELLED:       'none',
  EXPIRED:         'none',
  PAUSED:          'read_only',
}

export function getAccessLevel(status: string): AccessLevel {
  return ACCESS_MAP[status] ?? 'none'
}

export function hasFullAccess(status: string): boolean {
  return getAccessLevel(status) === 'full'
}

export function hasAnyAccess(status: string): boolean {
  return getAccessLevel(status) !== 'none'
}
