import api from './index'
import type { Goal } from './goal'
import type { Reminder } from './reminder'
import type { Task } from './task'
import type { Todo } from './todo'

export interface ScheduleCenterDaySummary {
  date: string
  todo_total: number
  todo_completed: number
  task_due_total: number
  high_priority_total: number
  reminder_total: number
  goal_total: number
}

export interface ScheduleCenterMonthResponse {
  month: string
  days: ScheduleCenterDaySummary[]
}

export interface ScheduleCenterDateResponse {
  date: string
  todos: Todo[]
  tasks: Task[]
  reminders: Reminder[]
  goals: Goal[]
  summary: ScheduleCenterDaySummary
  generated_at: string
}

export const scheduleCenterApi = {
  month(month: string) {
    const [year, monthValue] = month.split('-')
    return api.get<ScheduleCenterMonthResponse>('/api/schedule-center/month', {
      params: { year: Number(year), month: Number(monthValue) },
    })
  },

  date(date: string) {
    return api.get<ScheduleCenterDateResponse>('/api/schedule-center/date', { params: { date_str: date } })
  },
}
