import type { ScopeTier } from '@/business/scope/selectors';

export type TenantType = 'organization' | 'school' | 'campus' | 'class';
/** Tenant levels that can be a parent for creation. */
export type ParentLevel = 'organization' | 'school' | 'campus';

/** The parent tenant level a given type attaches to (null = top-level org). */
export function getRequiredParentLevel(type: TenantType): ParentLevel | null {
  switch (type) {
    case 'organization':
      return null;
    case 'school':
      return 'organization';
    case 'campus':
      return 'school';
    case 'class':
      return 'campus';
  }
}

/** Ordered tenant levels; index + 1 = depth (global = 0). */
export const TENANT_LEVELS: readonly ParentLevel[] = [
  'organization',
  'school',
  'campus',
];

export function levelDepth(level: ScopeTier | ParentLevel): number {
  switch (level) {
    case 'organization':
      return 1;
    case 'school':
      return 2;
    case 'campus':
      return 3;
    case 'class':
      return 4;
    default:
      // global / external
      return 0;
  }
}

export const TENANT_TYPE_LABELS: Record<TenantType, string> = {
  organization: 'Organization',
  school: 'School',
  campus: 'Campus',
  class: 'Class',
};
