import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
  createWalkthroughCheckin,
  deleteWalkthroughCheckin,
  listWalkthroughCheckins,
} from '@/shared/api/walkthrough';
import { apiRequest } from '@/shared/api/httpClient';
import type { WalkthroughCheckinCreateDto } from '@/shared/types/walkthrough';
import { WALKTHROUGH_TEST_SEED } from '@/test-seeds/walkthrough';

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

const apiRequestMock = vi.mocked(apiRequest);

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

  it('lists walkthrough check-ins without query parameters by default', () => {
    void listWalkthroughCheckins();

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

  it('lists walkthrough check-ins filtered by teacher name', () => {
    void listWalkthroughCheckins(WALKTHROUGH_TEST_SEED.teacherQueryName);

    expect(apiRequestMock).toHaveBeenCalledWith('/walkthrough_checkins?teacher_name=Test+Teacher');
  });

  it('creates walkthrough check-ins with POST body wrapped in data', () => {
    const request: WalkthroughCheckinCreateDto = {
      teacher_name: WALKTHROUGH_TEST_SEED.teacherName,
      classroom: WALKTHROUGH_TEST_SEED.classroom,
      director_name: WALKTHROUGH_TEST_SEED.directorName,
      check_in_date: '2026-06-08',
      check_in_time: '09:15',
      attitude_rating: 4,
      classroom_management_rating: 3,
      cleanliness_rating: 4,
      vibes_rating: 3,
      team_dynamics_rating: 4,
      emergency_exit_rating: 3,
      lesson_plan_rating: 2,
      overall_notes: 'Follow up on lesson plan posting.',
    };

    void createWalkthroughCheckin(request);

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

  it('deletes walkthrough check-ins through the item endpoint', () => {
    void deleteWalkthroughCheckin('checkin-1');

    expect(apiRequestMock).toHaveBeenCalledWith('/walkthrough_checkins/checkin-1', {
      method: 'DELETE',
    });
  });
});
