import { describe, expect, it } from 'vitest';
import {
  toFrameEntryMutationDto,
  toFrameEntryViewModel,
} from '@/business/frame/mappers';
import type { EditableFrameEntry } from '@/business/frame/types';
import type { FrameEntryDto } from '@/shared/types/frame';

describe('frame mappers', () => {
  it('maps backend FRAME DTO fields into the frontend view model shape', () => {
    const dto: FrameEntryDto = {
      id: 'frame-1',
      week_of: '2026-06-08',
      posted_date: '2026-06-08',
      formal: 'Formal note',
      recognition: 'Recognition note',
      application: 'Application note',
      management: 'Management note',
      emotional: 'Emotional note',
      author: 'Director',
      organizationId: 'org-1',
      campusId: 'campus-1',
      createdAt: '2026-06-08T10:00:00.000Z',
      updatedAt: '2026-06-08T10:00:00.000Z',
    };

    expect(toFrameEntryViewModel(dto)).toEqual({
      id: 'frame-1',
      weekOf: 'June 8, 2026',
      postedDate: 'June 8, 2026',
      formal: 'Formal note',
      recognition: 'Recognition note',
      application: 'Application note',
      management: 'Management note',
      emotional: 'Emotional note',
      author: 'Director',
    });
  });

  it('maps editable FRAME state back into the backend mutation DTO shape', () => {
    const entry: EditableFrameEntry = {
      weekOf: '2026-06-08',
      postedDate: '2026-06-09',
      formal: 'Formal',
      recognition: 'Recognition',
      application: 'Application',
      management: 'Management',
      emotional: 'Emotional',
      author: 'Office Manager',
    };

    expect(toFrameEntryMutationDto(entry)).toEqual({
      week_of: '2026-06-08',
      posted_date: '2026-06-09',
      formal: 'Formal',
      recognition: 'Recognition',
      application: 'Application',
      management: 'Management',
      emotional: 'Emotional',
      author: 'Office Manager',
    });
  });
});
