import { apiRequest } from '@/shared/api/httpClient';
import type { ApiListResponse } from '@/shared/types/api';
import type { ZoneColor } from '@/shared/types/app';
import type {
  ZoneCheckinHistoryEntryDto,
  ZoneCheckinCompletionDto,
  ZoneCheckinTodayDto,
} from '@/shared/types/zoneCheckins';

const ZONE_CHECKINS_PATH = '/zone_checkins';

export function getTodayZoneCheckin(): Promise<ZoneCheckinTodayDto> {
  return apiRequest<ZoneCheckinTodayDto>(`${ZONE_CHECKINS_PATH}/today`);
}

export function checkInZone(zone: ZoneColor): Promise<ZoneCheckinTodayDto> {
  return apiRequest<ZoneCheckinTodayDto>(ZONE_CHECKINS_PATH, {
    method: 'POST',
    body: { data: { zone } },
  });
}

export function clearTodayZoneCheckin(): Promise<ZoneCheckinTodayDto> {
  return apiRequest<ZoneCheckinTodayDto>(`${ZONE_CHECKINS_PATH}/today`, {
    method: 'DELETE',
  });
}

export function listZoneCheckinHistory(): Promise<
  ApiListResponse<ZoneCheckinHistoryEntryDto>
> {
  return apiRequest<ApiListResponse<ZoneCheckinHistoryEntryDto>>(
    ZONE_CHECKINS_PATH,
  );
}

export function getZoneCheckinCompletion(): Promise<ZoneCheckinCompletionDto> {
  return apiRequest<ZoneCheckinCompletionDto>(`${ZONE_CHECKINS_PATH}/completion`);
}
