import { api } from '@/lib/api'
import type { CorsRule } from '@/types/api'

export const corsService = {
    getAll: async (type: 'whitelist' | 'blacklist', _page = 1, _limit = 10) => {
        // Backend returns a flat array, not paginated
        const response = await api.get<CorsRule[]>(`/v1/settings/cors/${type}`)
        return response.data
    },

    create: async (type: 'whitelist' | 'blacklist', data: Partial<CorsRule>) => {
        const response = await api.post<CorsRule>(`/v1/settings/cors/${type}`, data)
        return response.data
    },

    update: async (type: 'whitelist' | 'blacklist', id: string, data: Partial<CorsRule>) => {
        const response = await api.put<CorsRule>(`/v1/settings/cors/${type}/${id}`, data)
        return response.data
    },

    delete: async (type: 'whitelist' | 'blacklist', id: string) => {
        await api.delete(`/v1/settings/cors/${type}/${id}`)
    }
}
