import { SafetyQuizResultCreateDto, SafetyQuizResultDto } from '@/shared/types/safetyQuiz';
import { SafetyQuizComplianceRow, SafetyQuizSubmission } from '@/business/safety-quiz/types';

function toRoleLabel(role: string): string {
  if (role === 'support_staff') {
    return 'Para';
  }

  if (role === 'director') {
    return 'Director';
  }

  if (role === 'superintendent') {
    return 'Superintendent';
  }

  if (role === 'office_manager') {
    return 'Office';
  }

  return 'Teacher';
}

export function toSafetyQuizComplianceRow(dto: SafetyQuizResultDto): SafetyQuizComplianceRow {
  return {
    name: dto.user_name,
    role: toRoleLabel(dto.user_role),
    status: 'complete',
    score: `${dto.score}/${dto.total_questions}`,
    date: new Date(dto.completed_at).toLocaleDateString('en-US', {
      month: 'short',
      day: 'numeric',
    }),
  };
}

export function toSafetyQuizResultCreateDto(submission: SafetyQuizSubmission): SafetyQuizResultCreateDto {
  return {
    quiz_id: submission.quizId,
    quiz_title: submission.quizTitle,
    week_of: submission.weekOf,
    score: submission.score,
    total_questions: submission.totalQuestions,
    answers: submission.answers,
  };
}
