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

export interface Sector {
    key: string;
    description: string;
    authorized: boolean;
}

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

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

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

    const response = await api.get<SectorListResponse>(`/v1/public/reference_data/sectors/?${params.toString()}`);
    if (!response.data) throw new Error('Error fetching sectors');
    return response.data;
}
