import api from './index'

export type GoalStatus = 'active' | 'done' | 'archived'

export interface Goal {
  id: string
  title: string
  note: string | null
  goal_date: string
  status: GoalStatus
  created_at: string
  updated_at: string
}

export interface GoalListResponse {
  items: Goal[]
}

export const goalApi = {
  list(date: string) {
    return api.get<GoalListResponse>('/api/goals', { params: { date_str: date } })
  },

  create(data: { title: string; goal_date: string; note?: string; status?: GoalStatus }) {
    return api.post<Goal>('/api/goals', data)
  },

  update(id: string, data: Partial<Pick<Goal, 'title' | 'note' | 'goal_date' | 'status'>>) {
    return api.patch<Goal>(`/api/goals/${id}`, data)
  },

  delete(id: string) {
    return api.delete(`/api/goals/${id}`)
  },
}
