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 'teacher':
      return 'Teacher';
    case 'para':
      return 'Support Staff';
    case 'office':
      return 'Office Manager';
    case 'director':
      return 'Director';
    case 'superintendent':
      return 'Superintendent';
  }
}
