export const RegistrationStatuses = [
    'submitted',
    'approved',
    'rejected',
] as const;

export type RegistrationStatus = (typeof RegistrationStatuses)[number];

export const RegistrationStatusLabels: Record<RegistrationStatus, string> = {
    submitted: 'Diajukan',
    approved: 'Disetujui',
    rejected: 'Ditolak',
};

export type CourseRegistrationStudent = {
    id: number;
    student_number: string;
    user: { profile: { full_name: string } | null } | null;
    department: { id: number; name: string } | null;
};

export type CourseRegistrationRow = {
    student_id: number;
    student: CourseRegistrationStudent | null;
};

export type DepartmentSummary = {
    id: number;
    name: string;
};

export type CourseRegistrationSubmissionLecturer = {
    lecturer_number: string;
    user: { profile: { full_name: string } | null } | null;
};

export type CourseRegistrationSubmissionStudent = {
    id: number;
    student_number: string;
    current_semester: number;
    department: {
        id: number;
        name: string;
        current_leader: {
            lecturer: CourseRegistrationSubmissionLecturer | null;
        } | null;
    } | null;
    user: { profile: { full_name: string } | null } | null;
    academic_advisor: CourseRegistrationSubmissionLecturer | null;
};

export type CourseRegistrationSubmissionEntry = {
    id: number;
    is_registered: boolean;
    course: {
        id: number;
        code: string;
        name: string;
        credits: number;
        semester_number: number | null;
    };
    course_class: {
        id: number;
    } | null;
};

export type CourseRegistrationSubmissionLog = {
    id: number;
    status: RegistrationStatus;
    reason: string | null;
    actor: { profile: { full_name: string } | null } | null;
    created_at: string;
};

export type CourseRegistrationSubmission = {
    id: number;
    status: RegistrationStatus;
    rejection_reason: string | null;
    signed_at: string;
    signature_url: string | null;
    kaprodi_signature_url: string | null;
    advisor_signature_url: string | null;
    has_registrations: boolean;
    student: CourseRegistrationSubmissionStudent | null;
    academic_term: {
        id: number;
        academic_year: string;
        semester: string;
    } | null;
    course_registrations: CourseRegistrationSubmissionEntry[];
    logs: CourseRegistrationSubmissionLog[];
};

export function semesterKey(semester: number | null): string {
    return semester === null ? 'lainnya' : String(semester);
}
