// SPDX-License-Identifier: Apache-2.0
import { K8ClientIngressClass } from './k8-client-ingress-class.js';
import { SoloError } from '../../../../../core/errors/solo-error.js';
import { ResourceCreateError, ResourceDeleteError } from '../../../errors/resource-operation-errors.js';
import { ResourceType } from '../../../resources/resource-type.js';
export class K8ClientIngressClasses {
    networkingApi;
    constructor(networkingApi) {
        this.networkingApi = networkingApi;
    }
    async list() {
        try {
            const response = await this.networkingApi.listIngressClass();
            const ingressClasses = [];
            if (response?.body?.items?.length > 0) {
                for (const item of response.body.items) {
                    ingressClasses.push(new K8ClientIngressClass(item.metadata?.name));
                }
            }
            return ingressClasses;
        }
        catch (error) {
            throw new SoloError('Failed to list IngressClasses:', error);
        }
    }
    async create(ingressClassName, controllerName) {
        const ingressClass = {
            apiVersion: 'networking.k8s.io/v1',
            kind: 'IngressClass',
            metadata: {
                name: ingressClassName,
            },
            spec: {
                controller: controllerName,
            },
        };
        try {
            await this.networkingApi.createIngressClass(ingressClass);
        }
        catch (error) {
            throw new ResourceCreateError(ResourceType.INGRESS_CLASS, undefined, ingressClassName, error);
        }
    }
    async delete(ingressClassName) {
        try {
            await this.networkingApi.deleteIngressClass(ingressClassName);
        }
        catch (error) {
            throw new ResourceDeleteError(ResourceType.INGRESS_CLASS, undefined, ingressClassName, error);
        }
    }
}
//# sourceMappingURL=k8-client-ingress-classes.js.map