"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BUILTIN_CONFIG_SCHEMAS = void 0;
const contracts_1 = require("../apis/codiac-api/contracts");
/** @see https://json-schema.org/learn/getting-started-step-by-step#create */
const footprintSchema = {
    $schema: "https://json-schema.org/draft/2020-12/schema",
    $id: "https://domain.codiac.io/container-footprint.config-schema.json",
    title: "ContainerFootprint Config Schema",
    description: "Available configuration setting names for specifying properties of a ContainerFootprint",
    type: "object",
    properties: {
        assetName: { type: "string" },
        replicas: { type: "number" },
        cpuRequest: { type: "string" },
        cpuLimit: { type: "string" },
        memRequest: { type: "string" },
        memLimit: { type: "string" },
        replicasMin: { type: "number" },
        replicasMax: { type: "number" },
        scaleBy: { type: "string" },
        scaling: {
            description: "Autoscaling profile",
            type: "object",
            properties: {
                max: { type: "number" },
                min: { type: "number" },
                disabled: { type: "boolean" },
                metrics: {
                    description: "Dictionary of the metric definitions by which the pods are to get scaled.  The value of each key can be set to either 'enabled', 'disabled', or a sparsely populated AutoscalingMetric definition.",
                    type: "object",
                    // dictionary...: "enabled" | "disabled" | IAutoscalingMetric } | undefined
                    // see https://stackoverflow.com/questions/27357861/dictionary-like-json-schema
                    additionalProperties: {
                        oneOf: [
                            {
                                enum: ["enabled", "disabled"]
                            },
                            {
                                description: "Autoscaling metric",
                                type: "object",
                                properties: {
                                    targetValue: { type: "number" },
                                    targetUnits: { type: "string" },
                                    disabled: { type: "boolean" }
                                }
                            }
                        ]
                    }
                }
                // , behavior: { type: "object" }  // TODO: <--- this
            },
            anyOf: [
                { required: ["max"] },
                { properties: { "disabled": { const: true } } }
            ]
        }
    },
    required: ["assetName" /* , "replicas" */]
};
/** THese are reflected in the relay as ProbeCallingSettingsEnum */
const probingSchema = {
    $schema: "https://json-schema.org/draft/2020-12/schema",
    $id: "https://domain.codiac.io/probing-behavior.config-schema.json",
    title: "ProbingBehavior Config Schema",
    description: "Available configuration setting names for specifying behavior overrides for health probes",
    type: "object",
    properties: {
        startup: {
            /// <reference path="" />
            type: "object",
            properties: {
                initialDelaySeconds: { type: "number" },
                periodSeconds: { type: "number" },
                timeoutSeconds: { type: "number" },
                successThreshold: { type: "number" },
                failureThreshold: { type: "number" },
                disabled: { type: "boolean" }
            }
        },
        liveness: {
            /// <reference path="" />
            type: "object",
            properties: {
                initialDelaySeconds: { type: "number" },
                periodSeconds: { type: "number" },
                timeoutSeconds: { type: "number" },
                successThreshold: { type: "number" },
                failureThreshold: { type: "number" },
                disabled: { type: "boolean" }
            }
        },
        readiness: {
            /// <reference path="" />
            type: "object",
            properties: {
                initialDelaySeconds: { type: "number" },
                periodSeconds: { type: "number" },
                timeoutSeconds: { type: "number" },
                successThreshold: { type: "number" },
                failureThreshold: { type: "number" },
                disabled: { type: "boolean" }
            }
        }
        // // TODO: Expand these into hierarchy (so we can support proper object schemas)...
        // ["startup.initialDelaySeconds"]: { type: "number" },
        // ["startup.periodSeconds"]: { type: "number" },
        // ["startup.timeoutSeconds"]: { type: "number" },
        // ["startup.successThreshold"]: { type: "number" },
        // ["startup.failureThreshold"]: { type: "number" },
        // ["startup.disabled"]: { type: "boolean" },
        // ["liveness.initialDelaySeconds"]: { type: "number" },
        // ["liveness.periodSeconds"]: { type: "number" },
        // ["liveness.timeoutSeconds"]: { type: "number" },
        // ["liveness.successThreshold"]: { type: "number" },
        // ["liveness.failureThreshold"]: { type: "number" },
        // ["liveness.disabled"]: { type: "boolean" },
        // ["readiness.initialDelaySeconds"]: { type: "number" },
        // ["readiness.periodSeconds"]: { type: "number" },
        // ["readiness.timeoutSeconds"]: { type: "number" },
        // ["readiness.successThreshold"]: { type: "number" },
        // ["readiness.failureThreshold"]: { type: "number" },
        // ["readiness.disabled"]: { type: "boolean" }
    },
    required: []
};
const k8spatchSchema = {
    $schema: "https://json-schema.org/draft/2020-12/schema",
    $id: "https://domain.codiac.io/k8spatch.config-schema.json",
    title: "K8sPatch Config Schema",
    description: "Available configuration setting names for specifying freeform overrides to raw Kubernetes entities on asset deploy",
    type: "object",
    definitions: {
        patchOperation: {
            type: "object",
            description: "A sequence of operations in JSON Patch format (see RFC-6902: https://datatracker.ietf.org/doc/html/rfc6902) to apply to a JSON document; it is suitable for use with the HTTP PATCH method.  The 'application/json-patch+json' media type is used to identify such patch documents.",
            properties: {
                op: {
                    enum: ["add", "copy", "move", "remove", "replace", "test"]
                },
                path: {
                    type: "string"
                },
                value: {}
            },
            required: ["op", "path", "value"]
        }
    },
    properties: {
        deployment: {
            type: "array",
            items: {
                $ref: "#/definitions/patchOperation"
            }
        },
        service: {
            type: "array",
            items: {
                $ref: "#/definitions/patchOperation"
            }
        },
        ingress: {
            type: "array",
            items: {
                $ref: "#/definitions/patchOperation"
            }
        },
    },
    required: []
};
/** Provides the available config settings for config types whose setting names are predefined. */
exports.BUILTIN_CONFIG_SCHEMAS = {
    [contracts_1.ConfigDefTypesEnum.footprint]: footprintSchema,
    [contracts_1.ConfigDefTypesEnum.probing]: probingSchema,
    [contracts_1.ConfigDefTypesEnum.k8spatch]: k8spatchSchema
};
//# sourceMappingURL=builtin-config-schemas.js.map