import { apiRequest } from '@/shared/api/httpClient';
import { ApiListResponse } from '@/shared/types/api';
import type {
  WalkthroughCheckinCreateDto,
  WalkthroughCheckinDto,
  WalkthroughDeleteResponse,
} from '@/shared/types/walkthrough';

const WALKTHROUGH_CHECKINS_PATH = '/walkthrough_checkins';

function createWalkthroughCheckinsPath(teacherName?: string): string {
  if (!teacherName) {
    return WALKTHROUGH_CHECKINS_PATH;
  }

  return `${WALKTHROUGH_CHECKINS_PATH}?${new URLSearchParams({ teacher_name: teacherName }).toString()}`;
}

export function listWalkthroughCheckins(teacherName?: string): Promise<ApiListResponse<WalkthroughCheckinDto>> {
  return apiRequest<ApiListResponse<WalkthroughCheckinDto>>(createWalkthroughCheckinsPath(teacherName));
}

export function createWalkthroughCheckin(request: WalkthroughCheckinCreateDto): Promise<WalkthroughCheckinDto> {
  return apiRequest<WalkthroughCheckinDto>(WALKTHROUGH_CHECKINS_PATH, {
    method: 'POST',
    body: { data: request },
  });
}

export function deleteWalkthroughCheckin(id: string): Promise<WalkthroughDeleteResponse> {
  return apiRequest<WalkthroughDeleteResponse>(`${WALKTHROUGH_CHECKINS_PATH}/${id}`, {
    method: 'DELETE',
  });
}
