import { describe, expect, it } from 'vitest';
import {
  toCampusAttendanceConfigViewModel,
  toCampusAttendanceSummaryMutationDto,
  toCampusAttendanceSummaryViewModel,
} from '@/business/campus-attendance/mappers';
import type { CampusAttendanceEntryInput } from '@/business/campus-attendance/types';
import type {
  CampusAttendanceConfigDto,
  CampusAttendanceSummaryDto,
} from '@/shared/types/campusAttendance';

describe('campus attendance mappers', () => {
  it('maps backend config DTO fields into the frontend view model shape', () => {
    const dto: CampusAttendanceConfigDto = {
      id: 'config-1',
      campus_key: 'tigers',
      attendance_link: 'https://attendance.example/north',
      updated_by_label: 'Office Manager',
      organizationId: 'org-1',
      campusId: 'campus-1',
      createdById: 'user-1',
      updatedById: 'user-2',
      createdAt: '2026-06-08T08:00:00.000Z',
      updatedAt: '2026-06-08T09:00:00.000Z',
    };

    expect(toCampusAttendanceConfigViewModel(dto)).toEqual({
      id: 'config-1',
      campus_id: 'tigers',
      attendance_link: 'https://attendance.example/north',
      updated_by: 'Office Manager',
      updated_at: '2026-06-08T09:00:00.000Z',
    });
  });

  it('maps backend summary DTO fields into the frontend view model shape', () => {
    const dto: CampusAttendanceSummaryDto = {
      id: 'summary-1',
      campus_key: 'gators',
      date: '2026-06-08',
      total_enrolled: 80,
      total_present: 72,
      total_absent: 6,
      total_tardy: 2,
      attendance_percentage: 90,
      recorded_by_label: 'Director',
      notes: 'Two late bus arrivals',
      organizationId: 'org-1',
      campusId: 'campus-2',
      createdById: 'user-3',
      updatedById: 'user-3',
      createdAt: '2026-06-08T10:00:00.000Z',
      updatedAt: '2026-06-08T10:15:00.000Z',
    };

    expect(toCampusAttendanceSummaryViewModel(dto)).toEqual({
      id: 'summary-1',
      campus_id: 'gators',
      date: '2026-06-08',
      total_enrolled: 80,
      total_present: 72,
      total_absent: 6,
      total_tardy: 2,
      attendance_percentage: 90,
      recorded_by: 'Director',
      notes: 'Two late bus arrivals',
    });
  });

  it('maps entry input back into the backend mutation DTO shape', () => {
    const input: CampusAttendanceEntryInput = {
      campusId: 'hawks',
      date: '2026-06-08',
      totalEnrolled: 42,
      totalPresent: 39,
      totalAbsent: 2,
      totalTardy: 1,
      notes: null,
    };

    expect(toCampusAttendanceSummaryMutationDto(input)).toEqual({
      total_enrolled: 42,
      total_present: 39,
      total_absent: 2,
      total_tardy: 1,
      notes: null,
    });
  });
});
