import type { CampusId, CampusInfo } from '@/shared/types/app';
import type { UserRole } from '@/shared/types/app';
import type { AuthModalDraft, AuthSignupStep } from '@/business/auth/types';

export function validateSignupStepOne(draft: AuthModalDraft): string | null {
  if (!draft.fullName.trim()) {
    return 'Please enter your full name';
  }

  if (!draft.email.trim() || !draft.email.includes('@')) {
    return 'Please enter a valid email address';
  }

  if (draft.password.length < 6) {
    return 'Password must be at least 6 characters';
  }

  if (draft.password !== draft.confirmPassword) {
    return 'Passwords do not match';
  }

  return null;
}

export function getNextSignupStep(step: AuthSignupStep): AuthSignupStep {
  if (step === 1) {
    return 2;
  }

  if (step === 2) {
    return 3;
  }

  return 3;
}

export function getPreviousSignupStep(step: AuthSignupStep): AuthSignupStep {
  if (step === 3) {
    return 2;
  }

  if (step === 2) {
    return 1;
  }

  return 1;
}

export function getSignupCampusName(campus: CampusId | '', campuses: readonly CampusInfo[]): string | null {
  if (!campus) {
    return null;
  }

  const selectedCampus = campuses.find((item) => item.id === campus);
  return selectedCampus?.mascot || campus;
}

export function getAuthRoleLabel(role: UserRole): string {
  switch (role) {
    case 'super_admin':
      return 'Super Admin';
    case 'system_admin':
      return 'System Admin';
    case 'owner':
      return 'Owner';
    case 'superintendent':
      return 'Superintendent';
    case 'director':
      return 'Director';
    case 'office_manager':
      return 'Office Manager';
    case 'teacher':
      return 'Teacher';
    case 'support_staff':
      return 'Support Staff';
    case 'student':
      return 'Student';
    case 'guardian':
      return 'Guardian';
    case 'guest':
      return 'Guest';
  }
}
