"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayMissingItems = exports.hasXmsEnum = exports.schemaHasEnum = exports.objectWithFormat = void 0;
const codemodel_v3_1 = require("@azure-tools/codemodel-v3");
const message = require("./messages");
const linq_1 = require("@azure-tools/linq");
function objectWithFormat(schema, state) {
    if (schema.type === codemodel_v3_1.JsonType.Object && schema.format) {
        state.error(`Schema is declared 'object' but has a format: '${schema.format}'`, message.ObjectShouldNotHaveFormat);
        return true;
    }
    return false;
}
exports.objectWithFormat = objectWithFormat;
function schemaHasEnum(schema, state) {
    if ((0, linq_1.length)(schema.enum) > 0) {
        state.error(`Schema with type:'${schema.type} and 'format:'${schema.format}' does not support 'enum' value restrictions.`, message.DoesNotSupportEnum);
        return true;
    }
    return false;
}
exports.schemaHasEnum = schemaHasEnum;
function hasXmsEnum(schema, state) {
    if ((0, linq_1.length)(schema.enum) > 0) {
        if (schema.extensions && schema.extensions['x-ms-enum']) {
            state.error(`Schema with type:'${schema.type} and 'format:'${schema.format}' does not support 'x-ms-enum' generation `, message.SchemaDoeNotSupportXMSEnum);
            return true;
        }
    }
    return false;
}
exports.hasXmsEnum = hasXmsEnum;
function arrayMissingItems(schema, state) {
    if (schema.type === codemodel_v3_1.JsonType.Array && !schema.items) {
        state.error('Array schema missing items type', message.ArrayMissingItems);
        return true;
    }
    return false;
}
exports.arrayMissingItems = arrayMissingItems;
//# sourceMappingURL=validations.js.map