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

export interface Trailer {
    trailer_number: string;
    plate_number?: string;
    trailer_type_key?: string;
    is_active: boolean;
    tenant_id?: string;
}

export interface TrailerResponse {
    items: Trailer[];
    total: number;
    page: number;
    page_size: number;
}

class TrailersApi {
    private baseUrl = '/v1/a76/trailers';

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

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

export const trailersApi = new TrailersApi();
