"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeAiExtractStructuredMetadataTemplateTypeField = serializeAiExtractStructuredMetadataTemplateTypeField;
exports.deserializeAiExtractStructuredMetadataTemplateTypeField = deserializeAiExtractStructuredMetadataTemplateTypeField;
exports.serializeAiExtractStructuredMetadataTemplateField = serializeAiExtractStructuredMetadataTemplateField;
exports.deserializeAiExtractStructuredMetadataTemplateField = deserializeAiExtractStructuredMetadataTemplateField;
exports.serializeAiExtractStructuredFieldsOptionsField = serializeAiExtractStructuredFieldsOptionsField;
exports.deserializeAiExtractStructuredFieldsOptionsField = deserializeAiExtractStructuredFieldsOptionsField;
exports.serializeAiExtractStructuredFieldsField = serializeAiExtractStructuredFieldsField;
exports.deserializeAiExtractStructuredFieldsField = deserializeAiExtractStructuredFieldsField;
exports.serializeAiExtractStructured = serializeAiExtractStructured;
exports.deserializeAiExtractStructured = deserializeAiExtractStructured;
const aiItemBase_1 = require("./aiItemBase.js");
const aiItemBase_2 = require("./aiItemBase.js");
const aiExtractStructuredAgent_1 = require("./aiExtractStructuredAgent.js");
const aiExtractStructuredAgent_2 = require("./aiExtractStructuredAgent.js");
const errors_1 = require("../box/errors.js");
const json_1 = require("../serialization/json.js");
const json_2 = require("../serialization/json.js");
const json_3 = require("../serialization/json.js");
const json_4 = require("../serialization/json.js");
function serializeAiExtractStructuredMetadataTemplateTypeField(val) {
    return val;
}
function deserializeAiExtractStructuredMetadataTemplateTypeField(val) {
    if (val == 'metadata_template') {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize AiExtractStructuredMetadataTemplateTypeField",
    });
}
function serializeAiExtractStructuredMetadataTemplateField(val) {
    return {
        ['template_key']: val.templateKey,
        ['type']: val.type == void 0
            ? val.type
            : serializeAiExtractStructuredMetadataTemplateTypeField(val.type),
        ['scope']: val.scope,
    };
}
function deserializeAiExtractStructuredMetadataTemplateField(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AiExtractStructuredMetadataTemplateField"',
        });
    }
    if (!(val.template_key == void 0) && !(0, json_2.sdIsString)(val.template_key)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "template_key" of type "AiExtractStructuredMetadataTemplateField"',
        });
    }
    const templateKey = val.template_key == void 0 ? void 0 : val.template_key;
    const type = val.type == void 0
        ? void 0
        : deserializeAiExtractStructuredMetadataTemplateTypeField(val.type);
    if (!(val.scope == void 0) && !(0, json_2.sdIsString)(val.scope)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "scope" of type "AiExtractStructuredMetadataTemplateField"',
        });
    }
    const scope = val.scope == void 0 ? void 0 : val.scope;
    return {
        templateKey: templateKey,
        type: type,
        scope: scope,
    };
}
function serializeAiExtractStructuredFieldsOptionsField(val) {
    return { ['key']: val.key };
}
function deserializeAiExtractStructuredFieldsOptionsField(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AiExtractStructuredFieldsOptionsField"',
        });
    }
    if (val.key == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "key" of type "AiExtractStructuredFieldsOptionsField" to be defined',
        });
    }
    if (!(0, json_2.sdIsString)(val.key)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "key" of type "AiExtractStructuredFieldsOptionsField"',
        });
    }
    const key = val.key;
    return { key: key };
}
function serializeAiExtractStructuredFieldsField(val) {
    return {
        ['key']: val.key,
        ['description']: val.description,
        ['displayName']: val.displayName,
        ['prompt']: val.prompt,
        ['type']: val.type,
        ['options']: val.options == void 0
            ? val.options
            : val.options.map(function (item) {
                return serializeAiExtractStructuredFieldsOptionsField(item);
            }),
    };
}
function deserializeAiExtractStructuredFieldsField(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AiExtractStructuredFieldsField"',
        });
    }
    if (val.key == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "key" of type "AiExtractStructuredFieldsField" to be defined',
        });
    }
    if (!(0, json_2.sdIsString)(val.key)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "key" of type "AiExtractStructuredFieldsField"',
        });
    }
    const key = val.key;
    if (!(val.description == void 0) && !(0, json_2.sdIsString)(val.description)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "description" of type "AiExtractStructuredFieldsField"',
        });
    }
    const description = val.description == void 0 ? void 0 : val.description;
    if (!(val.displayName == void 0) && !(0, json_2.sdIsString)(val.displayName)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "displayName" of type "AiExtractStructuredFieldsField"',
        });
    }
    const displayName = val.displayName == void 0 ? void 0 : val.displayName;
    if (!(val.prompt == void 0) && !(0, json_2.sdIsString)(val.prompt)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "prompt" of type "AiExtractStructuredFieldsField"',
        });
    }
    const prompt = val.prompt == void 0 ? void 0 : val.prompt;
    if (!(val.type == void 0) && !(0, json_2.sdIsString)(val.type)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "type" of type "AiExtractStructuredFieldsField"',
        });
    }
    const type = val.type == void 0 ? void 0 : val.type;
    if (!(val.options == void 0) && !(0, json_3.sdIsList)(val.options)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting array for "options" of type "AiExtractStructuredFieldsField"',
        });
    }
    const options = val.options == void 0
        ? void 0
        : (0, json_3.sdIsList)(val.options)
            ? val.options.map(function (itm) {
                return deserializeAiExtractStructuredFieldsOptionsField(itm);
            })
            : [];
    return {
        key: key,
        description: description,
        displayName: displayName,
        prompt: prompt,
        type: type,
        options: options,
    };
}
function serializeAiExtractStructured(val) {
    return {
        ['items']: val.items.map(function (item) {
            return (0, aiItemBase_1.serializeAiItemBase)(item);
        }),
        ['metadata_template']: val.metadataTemplate == void 0
            ? val.metadataTemplate
            : serializeAiExtractStructuredMetadataTemplateField(val.metadataTemplate),
        ['fields']: val.fields == void 0
            ? val.fields
            : val.fields.map(function (item) {
                return serializeAiExtractStructuredFieldsField(item);
            }),
        ['ai_agent']: val.aiAgent == void 0
            ? val.aiAgent
            : (0, aiExtractStructuredAgent_1.serializeAiExtractStructuredAgent)(val.aiAgent),
        ['include_confidence_score']: val.includeConfidenceScore,
        ['include_reference']: val.includeReference,
    };
}
function deserializeAiExtractStructured(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "AiExtractStructured"',
        });
    }
    if (val.items == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "items" of type "AiExtractStructured" to be defined',
        });
    }
    if (!(0, json_3.sdIsList)(val.items)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting array for "items" of type "AiExtractStructured"',
        });
    }
    const items = (0, json_3.sdIsList)(val.items)
        ? val.items.map(function (itm) {
            return (0, aiItemBase_2.deserializeAiItemBase)(itm);
        })
        : [];
    const metadataTemplate = val.metadata_template == void 0
        ? void 0
        : deserializeAiExtractStructuredMetadataTemplateField(val.metadata_template);
    if (!(val.fields == void 0) && !(0, json_3.sdIsList)(val.fields)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting array for "fields" of type "AiExtractStructured"',
        });
    }
    const fields = val.fields == void 0
        ? void 0
        : (0, json_3.sdIsList)(val.fields)
            ? val.fields.map(function (itm) {
                return deserializeAiExtractStructuredFieldsField(itm);
            })
            : [];
    const aiAgent = val.ai_agent == void 0
        ? void 0
        : (0, aiExtractStructuredAgent_2.deserializeAiExtractStructuredAgent)(val.ai_agent);
    if (!(val.include_confidence_score == void 0) &&
        !(0, json_1.sdIsBoolean)(val.include_confidence_score)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting boolean for "include_confidence_score" of type "AiExtractStructured"',
        });
    }
    const includeConfidenceScore = val.include_confidence_score == void 0
        ? void 0
        : val.include_confidence_score;
    if (!(val.include_reference == void 0) &&
        !(0, json_1.sdIsBoolean)(val.include_reference)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting boolean for "include_reference" of type "AiExtractStructured"',
        });
    }
    const includeReference = val.include_reference == void 0 ? void 0 : val.include_reference;
    return {
        items: items,
        metadataTemplate: metadataTemplate,
        fields: fields,
        aiAgent: aiAgent,
        includeConfidenceScore: includeConfidenceScore,
        includeReference: includeReference,
    };
}
//# sourceMappingURL=aiExtractStructured.js.map