import { api } from './api'; export type ChallengeStatus = 'upcoming' | 'ongoing' | 'expired'; export type ChallengeProgressDto = { completed: number; target: number; remaining: number; badge: string; subtitle?: string; }; export type RankingItemDto = { id: string; name: string; avatar: string | null; metric: string; badge?: string; }; export type ChallengeListItemDto = { id: string; title: string; image: string; periodLabel?: string; durationLabel: string; requirementLabel: string; status: ChallengeStatus; participantsCount: number; rankingDescription?: string; highlightTitle: string; highlightSubtitle: string; ctaLabel: string; progress?: ChallengeProgressDto; isJoined: boolean; startAt?: string; endAt?: string; }; export type ChallengeDetailDto = ChallengeListItemDto & { summary?: string; rankings: RankingItemDto[]; userRank?: number; }; export async function listChallenges(): Promise { return api.get('/challenges'); } export async function getChallengeDetail(id: string): Promise { return api.get(`/challenges/${encodeURIComponent(id)}`); } export async function joinChallenge(id: string): Promise { return api.post(`/challenges/${encodeURIComponent(id)}/join`); } export async function leaveChallenge(id: string): Promise { return api.post(`/challenges/${encodeURIComponent(id)}/leave`); } export async function reportChallengeProgress(id: string, increment?: number): Promise { const body = increment != null ? { increment } : undefined; return api.post(`/challenges/${encodeURIComponent(id)}/progress`, body); }