import { ApiClient, type ApiClientOptions } from "../infra/client"
import type { ApiPath, ApiResponse } from "../infra/types"

export const HOME_ROUTES = {
    DASHBOARD: "/api/home",
} as const satisfies Record<string, ApiPath>

export const DashboardPeriods = [
    "today",
    "yesterday",
    "this_week",
    "this_month",
    "last_month",
    "last_3_months",
    "last_6_months",
    "last_year",
    "year_to_date",
    "all_time",
    "custom",
] as const

export type DashboardPeriod = (typeof DashboardPeriods)[number]

export type HomeDashboardQuery = {
    period?: DashboardPeriod
    start_date?: string
    end_date?: string
    financial_period?: DashboardPeriod
    financial_start_date?: string
    financial_end_date?: string
    work_order_period?: DashboardPeriod
    work_order_start_date?: string
    work_order_end_date?: string
    appointment_period?: DashboardPeriod
    appointment_start_date?: string
    appointment_end_date?: string
    sales_period?: DashboardPeriod
    sales_start_date?: string
    sales_end_date?: string
    purchase_period?: DashboardPeriod
    purchase_start_date?: string
    purchase_end_date?: string
    upcoming_filter?: "today" | "tomorrow" | "this_week" | "next_week"
    upcoming_per_page?: number
    upcoming_page?: number
}

export type HomeDashboardResponse = ApiResponse<typeof HOME_ROUTES.DASHBOARD, "get">

export class HomeClient extends ApiClient {
    constructor(baseUrl?: string, defaultOptions?: ApiClientOptions) {
        super(baseUrl, defaultOptions)
    }

    async dashboard(query?: HomeDashboardQuery) {
        return this.get(
            HOME_ROUTES.DASHBOARD,
            query
                ? ({
                      query,
                  } as never)
                : undefined,
        )
    }
}
