// SPDX-License-Identifier: Apache-2.0
import { container } from 'tsyringe-neo';
import { InjectTokens } from '../../../../../core/dependency-injection/inject-tokens.js';
import { KubeApiResponse } from '../../../kube-api-response.js';
import { ResourceOperation } from '../../../resources/resource-operation.js';
import { ResourceType } from '../../../resources/resource-type.js';
export class K8ClientCrds {
    networkingApi;
    logger;
    constructor(networkingApi) {
        this.networkingApi = networkingApi;
        this.logger = container.resolve(InjectTokens.SoloLogger);
    }
    async ifExists(crdName) {
        try {
            await this.networkingApi.readCustomResourceDefinition({
                name: crdName,
            });
            this.logger.debug(`CRD ${crdName} exists.`);
        }
        catch (error) {
            if (KubeApiResponse.isNotFound(error)) {
                this.logger.info(`CRD ${crdName} does not exist.`);
                return false;
            }
            KubeApiResponse.throwError(error, ResourceOperation.READ, ResourceType.CLUSTER_ROLE_DEFINITION, undefined, crdName);
        }
        return true;
    }
}
//# sourceMappingURL=k8-client-crds.js.map