import { useFetchJson } from './useFetchJson'

const API_PREFIX = '/api/v1/restricted/repo'

export interface QuarterData {
    quarter: string
    time: number
}

export interface IssueTimeSummary {
    IssueID: number
    IssueName: string
    UserId: number
    Initials: string
    CreatedDate: string
    TotalHoursSpent: number
}

export interface IssueResponse {
    items: IssueTimeSummary[]
    count: number
}

export interface PagingParams {
    page?: number
    pageSize?: number
}

// export async function getRepos(): Promise<any> {
//     const result = await useFetchJson<number[]>(`${API_PREFIX}/get-repos`)
//     return result
// }

// export async function getYears(repoID: number): Promise<any> {
//     return useFetchJson<number[]>(`${API_PREFIX}/get-years?repoID=${repoID}`)
// }

export async function getYears(repoID: number): Promise<any> {
    return useFetchJson<number[]>(`${API_PREFIX}/get-years?repoID=${repoID}`);
}

// Correct way to log the data

export async function getQuarters(repoID: number, year: number): Promise<any> {
    return useFetchJson<QuarterData[]>(`${API_PREFIX}/get-quarters?repoID=${repoID}&year=${year}`)
}

// export async function getIssues(
//     repoID: number,
//     year: number,
//     quarter: number,
//     page: number = 1,
//     pageSize: number = 10
// ): Promise<any> {
//     // The get-issues endpoint uses GET with pagination in query params
//     return useFetchJson<IssueResponse>(
//         `${API_PREFIX}/get-issues?repoID=${repoID}&year=${year}&quarter=${quarter}&page_number=${page}&elements_per_page=${pageSize}`
//     )
// }
// async function logYears() {
//     const years = await getIssues(7); // pass a repoID
// }
export async function getIssues(
    repoID: number,
    year: number,
    quarter: number,
    page: number = 1,
    pageSize: number = 10
): Promise<any> {
    return useFetchJson<IssueResponse>(
        `${API_PREFIX}/get-issues?repoID=${repoID}&year=${year}&quarter=${quarter}&page_number=${page}&elements_per_page=${pageSize}`
    );
}
