import { api, type ApiResponse } from '$lib/api';

export interface Driver {
    transporter_key: string;
    line: number;
    driver_name?: string;
    license_number?: string;
    express_line_id?: string;
    ace_id?: string;
    birth_date?: number;
    gender?: string;
    birth_country?: string;
    hazardous_material_auth?: string;
    hazardous_material_state?: string;
    first_name?: string;
    last_name?: string;
    badge_number?: string;
    class_type?: string;
}

export interface DriverResponse {
    items: Driver[];
    total: number;
    page: number;
    page_size: number;
}

class DriversApi {
    private baseUrl = '/v1/a76/drivers';

    async list(
        companyId: string | number,
        page: number = 1,
        pageSize: number = 50
    ): Promise<ApiResponse<DriverResponse>> {
        const params = new URLSearchParams({
            company_id: companyId.toString(),
            page: page.toString(),
            page_size: pageSize.toString()
        });

        return api.get<DriverResponse>(`${this.baseUrl}?${params.toString()}`);
    }

    async get(
        transporterKey: string,
        line: number,
        companyId: string | number
    ): Promise<ApiResponse<Driver>> {
        const params = new URLSearchParams({
            company_id: companyId.toString()
        });
        return api.get<Driver>(`${this.baseUrl}/${transporterKey}/${line}?${params.toString()}`);
    }
}

export const driversApi = new DriversApi();
