import type {
  CreateClipPayload,
  CreateShowactApplicationPayload,
  CreateNominationPayload,
  CreateVotePayload,
  OverviewResponse,
  PublicSiteStatusResponse,
  PublicSponsorsResponse,
  SeasonCategoriesResponse,
  UserParticipationResponse,
  WinnerArchiveResponse,
} from '../../types/awards'
import { requestJson } from '../http'
import { jsonRequest } from './requestOptions'

export const publicApi = {
  getOverview: () => requestJson<OverviewResponse>('/api/public/overview'),
  getSiteStatus: () => requestJson<PublicSiteStatusResponse>('/api/public/site-status'),
  getSeasonCategories: (year: number) =>
    requestJson<SeasonCategoriesResponse>(`/api/public/seasons/${year}/categories`),
  getWinnerArchive: (year: number) =>
    requestJson<WinnerArchiveResponse>(`/api/public/seasons/${year}/winners`),
  getPublicSponsors: (year: number) =>
    requestJson<PublicSponsorsResponse>(`/api/public/seasons/${year}/sponsors`),
  getMyParticipation: (year: number) =>
    requestJson<UserParticipationResponse>(`/api/public/seasons/${year}/me`),
  submitNomination: (payload: CreateNominationPayload) =>
    requestJson<{ saved: number; category: string }>('/api/public/nominations', jsonRequest('POST', payload)),
  submitVote: (payload: CreateVotePayload) =>
    requestJson<{ ballotId: number; entries: number }>('/api/public/votes', jsonRequest('POST', payload)),
  submitClip: (payload: CreateClipPayload) =>
    requestJson<{ saved: boolean; clipId: number }>('/api/public/clips', jsonRequest('POST', payload)),
  submitShowactApplication: (payload: CreateShowactApplicationPayload) =>
    requestJson<{ saved: boolean; applicationId: number }>('/api/public/showacts', jsonRequest('POST', payload)),
}
