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

export interface Transporter {
    transporter_key: string;
    name: string;
    rfc?: string;
    is_active: boolean;
    tenant_id?: string;
}

export interface TransporterResponse {
    items: Transporter[];
    total: number;
    page: number;
    page_size: number;
}

class TransportersApi {
    private baseUrl = '/v1/a76/transporters';

    async list(
        companyId: string | number,
        params?: Record<string, any>
    ): Promise<ApiResponse<TransporterResponse>> {
        const queryParams = new URLSearchParams({
            company_id: companyId.toString(),
            ...params
        });
        return api.get<TransporterResponse>(`${this.baseUrl}?${queryParams.toString()}`);
    }

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

export const transportersApi = new TransportersApi();
