import { adminHttp } from './http' import type { FormSchemaPayload, FormSchemaRow } from './types' export async function listFormSchemas(competitionId: number, purpose?: 'signup' | 'review'): Promise { const { data } = await adminHttp.get(`/competitions/${competitionId}/form-schemas`, { params: purpose ? { purpose } : {}, }) const body = data as { data?: FormSchemaRow[] } return body.data ?? [] } export async function getFormSchema(competitionId: number, schemaId: number): Promise { const { data } = await adminHttp.get(`/competitions/${competitionId}/form-schemas/${schemaId}`) const body = (data as { data?: FormSchemaRow })?.data ?? (data as FormSchemaRow) if (!body || typeof body !== 'object' || !('id' in body)) throw new Error('表单详情无效') return body as FormSchemaRow } export async function createFormSchema(competitionId: number, payload: FormSchemaPayload): Promise { const { data } = await adminHttp.post(`/competitions/${competitionId}/form-schemas`, payload) return data } export async function updateFormSchema( competitionId: number, schemaId: number, payload: Partial<{ name: string; schema_json: unknown[]; is_published: boolean }>, ): Promise { const { data } = await adminHttp.patch( `/competitions/${competitionId}/form-schemas/${schemaId}`, payload, ) return data } export async function deleteFormSchema(competitionId: number, schemaId: number): Promise { await adminHttp.delete(`/competitions/${competitionId}/form-schemas/${schemaId}`) }