import api from "../axios";

export interface ScheduleStatus {
  id: string;
  name: string;
  color: string | null;
}

export interface ScheduleType {
  id: string;
  name: string;
  displayColor: string | null;
}

export interface ScheduleSpan {
  id: string;
  scheduleSpanId: number | null;
  spanDesc: string | null;
}

export interface ScheduleEntry {
  id: string;
  cwId: number;
  memberId: string | null;
  name: string;
  description: string | null;
  allDayFlag: boolean;
  startDate: string | null;
  endDate: string | null;
  hoursScheduled: number | null;
  status: ScheduleStatus | null;
  type: ScheduleType | null;
  scheduleSpan: ScheduleSpan | null;
}

export const schedule = {
  async fetchMe(
    accessToken: string,
    start: Date,
    end: Date,
  ): Promise<ScheduleEntry[]> {
    const response = await api.get("/v1/schedule/@me", {
      params: {
        start: start.toISOString(),
        end: end.toISOString(),
      },
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
    });
    return (response.data?.data as ScheduleEntry[]) ?? [];
  },
};
