/**
 * Copyright (C) 2024 Hedera Hashgraph, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the ""License"");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an ""AS IS"" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
import { registerDecorator } from 'class-validator';
const isObject = obj => obj === Object(obj);
export const IsDeployments = (validationOptions) => {
    return function (object, propertyName) {
        registerDecorator({
            name: 'IsDeployments',
            target: object.constructor,
            propertyName: propertyName,
            constraints: [],
            options: {
                ...validationOptions,
            },
            validator: {
                validate(value, args) {
                    if (!isObject(value))
                        return false;
                    if (Object.keys(value).length === 0)
                        return true;
                    const keys = Object.keys(value);
                    return keys.every(key => {
                        if (typeof key !== 'string')
                            return false;
                        if (!isObject(value[key]))
                            return false;
                        if (!Array.isArray(value[key].clusters))
                            return false;
                        if (!value[key].clusters.every(val => typeof val === 'string'))
                            return false;
                        return true;
                    });
                },
            },
        });
    };
};
export const IsClusterContextMapping = (validationOptions) => {
    return function (object, propertyName) {
        registerDecorator({
            name: 'IsClusterContextMapping',
            target: object.constructor,
            propertyName: propertyName,
            constraints: [],
            options: {
                ...validationOptions,
            },
            validator: {
                validate(value, args) {
                    if (!isObject(value))
                        return false;
                    if (Object.keys(value).length === 0)
                        return true;
                    // TODO expand the validation. Check if the context exists in the local kube config
                    //  and that it can actually establish a connection to the cluster
                    for (const clusterName in value) {
                        const contextName = value[clusterName];
                        if (typeof clusterName !== 'string' || typeof contextName !== 'string') {
                            return false;
                        }
                    }
                    return true;
                },
            },
        });
    };
};
//# sourceMappingURL=validator_decorators.js.map