import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
  createFrameEntry,
  listFrameEntries,
  updateFrameEntry,
} from '@/shared/api/frame';
import { apiRequest } from '@/shared/api/httpClient';
import type { FrameEntryMutationDto } from '@/shared/types/frame';

vi.mock('@/shared/api/httpClient', () => ({
  apiRequest: vi.fn(),
}));

const apiRequestMock = vi.mocked(apiRequest);

const frameRequest: FrameEntryMutationDto = {
  week_of: '2026-06-08',
  posted_date: '2026-06-08',
  formal: 'Formal',
  recognition: 'Recognition',
  application: 'Application',
  management: 'Management',
  emotional: 'Emotional',
  author: 'Director',
};

describe('frame API', () => {
  beforeEach(() => {
    apiRequestMock.mockReset();
  });

  it('lists FRAME entries through the collection endpoint', () => {
    void listFrameEntries();

    expect(apiRequestMock).toHaveBeenCalledWith('/frame_entries');
  });

  it('creates FRAME entries with POST body wrapped in data', () => {
    void createFrameEntry(frameRequest);

    expect(apiRequestMock).toHaveBeenCalledWith('/frame_entries', {
      method: 'POST',
      body: { data: frameRequest },
    });
  });

  it('updates FRAME entries with PUT body wrapped in data', () => {
    void updateFrameEntry('frame-1', frameRequest);

    expect(apiRequestMock).toHaveBeenCalledWith('/frame_entries/frame-1', {
      method: 'PUT',
      body: { data: frameRequest },
    });
  });
});
