import { api } from '@/services/api'; export type CheckinMetrics = Record; export type CreateCheckinDto = { workoutId?: string; planId?: string; title?: string; checkinDate?: string; // YYYY-MM-DD startedAt?: string; // ISO notes?: string; metrics?: CheckinMetrics; }; export type UpdateCheckinDto = Partial & { id: string; status?: string; // 由后端验证为 CheckinStatus completedAt?: string; // ISO durationSeconds?: number; }; export type CompleteCheckinDto = { id: string; completedAt?: string; // ISO durationSeconds?: number; notes?: string; metrics?: CheckinMetrics; }; export type RemoveCheckinDto = { id: string; }; export async function createCheckin(dto: CreateCheckinDto): Promise<{ id: string } & Record> { return await api.post('/api/checkins/create', dto); } export async function updateCheckin(dto: UpdateCheckinDto): Promise<{ id: string } & Record> { return await api.put('/api/checkins/update', dto); } export async function completeCheckin(dto: CompleteCheckinDto): Promise<{ id: string } & Record> { return await api.post('/api/checkins/complete', dto); } export async function removeCheckin(dto: RemoveCheckinDto): Promise> { return await api.delete('/api/checkins/remove', { body: dto }); } // 按天获取打卡列表(后端默认今天,不传 date 也可) export async function fetchDailyCheckins(date?: string): Promise { const path = date ? `/api/checkins/daily?date=${encodeURIComponent(date)}` : '/api/checkins/daily'; const data = await api.get(path); // 返回值兼容 { data: T } 或直接 T 已由 api 封装处理 return Array.isArray(data) ? data : []; }