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

export interface Sector {
    id: number;
    key: string;
    description: string;
    authorized: boolean;
    company_id: number;
    tenant_id: number;
    created_at?: string;
    updated_at?: string;
}

export interface SectorListResponse {
    items: Sector[];
    total: number;
    page: number;
    page_size: number;
}

export async function getSectors(
    page = 1,
    pageSize = 50,
    companyId: number,
    search?: string
): Promise<ApiResponse<SectorListResponse>> {
    const params = new URLSearchParams({
        page: page.toString(),
        page_size: pageSize.toString(),
        company_id: companyId.toString()
    });

    if (search) {
        params.append('key', search);
    }

    return await api.get<SectorListResponse>(`/v1/a76/sectors/?${params.toString()}`);
}
