import { BoxSdkError } from '../box/errors.js';
import { sdIsBoolean } from '../serialization/json.js';
import { sdIsNumber } from '../serialization/json.js';
import { sdIsString } from '../serialization/json.js';
import { sdIsList } from '../serialization/json.js';
import { sdIsMap } from '../serialization/json.js';
export class MetadataTemplate {
    /**
     * The ID of the metadata template. */
    id;
    /**
     * The value will always be `metadata_template`. */
    type = 'metadata_template';
    /**
     * The scope of the metadata template can either be `global` or
     * `enterprise_*`. The `global` scope is used for templates that are
     * available to any Box enterprise. The `enterprise_*` scope represents
     * templates that have been created within a specific enterprise, where `*`
     * will be the ID of that enterprise. */
    scope;
    /**
     * A unique identifier for the template. This identifier is unique across
     * the `scope` of the enterprise to which the metadata template is being
     * applied, yet is not necessarily unique across different enterprises. */
    templateKey;
    /**
     * The display name of the template. This can be seen in the Box web app
     * and mobile apps. */
    displayName;
    /**
     * Defines if this template is visible in the Box web app UI, or if
     * it is purely intended for usage through the API. */
    hidden;
    /**
     * An ordered list of template fields which are part of the template. Each
     * field can be a regular text field, date field, number field, as well as a
     * single or multi-select list. */
    fields;
    /**
     * Whether or not to include the metadata when a file or folder is copied. */
    copyInstanceOnItemCopy;
    rawData;
    constructor(fields) {
        if (fields.id !== undefined) {
            this.id = fields.id;
        }
        if (fields.type !== undefined) {
            this.type = fields.type;
        }
        if (fields.scope !== undefined) {
            this.scope = fields.scope;
        }
        if (fields.templateKey !== undefined) {
            this.templateKey = fields.templateKey;
        }
        if (fields.displayName !== undefined) {
            this.displayName = fields.displayName;
        }
        if (fields.hidden !== undefined) {
            this.hidden = fields.hidden;
        }
        if (fields.fields !== undefined) {
            this.fields = fields.fields;
        }
        if (fields.copyInstanceOnItemCopy !== undefined) {
            this.copyInstanceOnItemCopy = fields.copyInstanceOnItemCopy;
        }
        if (fields.rawData !== undefined) {
            this.rawData = fields.rawData;
        }
    }
}
export function serializeMetadataTemplateTypeField(val) {
    return val;
}
export function deserializeMetadataTemplateTypeField(val) {
    if (val == 'metadata_template') {
        return val;
    }
    throw new BoxSdkError({
        message: "Can't deserialize MetadataTemplateTypeField",
    });
}
export function serializeMetadataTemplateFieldsTypeField(val) {
    return val;
}
export function deserializeMetadataTemplateFieldsTypeField(val) {
    if (val == 'string') {
        return val;
    }
    if (val == 'float') {
        return val;
    }
    if (val == 'date') {
        return val;
    }
    if (val == 'enum') {
        return val;
    }
    if (val == 'multiSelect') {
        return val;
    }
    if (val == 'taxonomy') {
        return val;
    }
    if (val == 'integer') {
        return val;
    }
    throw new BoxSdkError({
        message: "Can't deserialize MetadataTemplateFieldsTypeField",
    });
}
export function serializeMetadataTemplateFieldsOptionsField(val) {
    return { ['key']: val.key, ['id']: val.id };
}
export function deserializeMetadataTemplateFieldsOptionsField(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "MetadataTemplateFieldsOptionsField"',
        });
    }
    if (val.key == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "key" of type "MetadataTemplateFieldsOptionsField" to be defined',
        });
    }
    if (!sdIsString(val.key)) {
        throw new BoxSdkError({
            message: 'Expecting string for "key" of type "MetadataTemplateFieldsOptionsField"',
        });
    }
    const key = val.key;
    if (!(val.id == void 0) && !sdIsString(val.id)) {
        throw new BoxSdkError({
            message: 'Expecting string for "id" of type "MetadataTemplateFieldsOptionsField"',
        });
    }
    const id = val.id == void 0 ? void 0 : val.id;
    return { key: key, id: id };
}
export function serializeMetadataTemplateFieldsOptionsRulesField(val) {
    return {
        ['multiSelect']: val.multiSelect,
        ['selectableLevels']: val.selectableLevels == void 0
            ? val.selectableLevels
            : val.selectableLevels.map(function (item) {
                return item;
            }),
    };
}
export function deserializeMetadataTemplateFieldsOptionsRulesField(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "MetadataTemplateFieldsOptionsRulesField"',
        });
    }
    if (!(val.multiSelect == void 0) && !sdIsBoolean(val.multiSelect)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "multiSelect" of type "MetadataTemplateFieldsOptionsRulesField"',
        });
    }
    const multiSelect = val.multiSelect == void 0 ? void 0 : val.multiSelect;
    if (!(val.selectableLevels == void 0) && !sdIsList(val.selectableLevels)) {
        throw new BoxSdkError({
            message: 'Expecting array for "selectableLevels" of type "MetadataTemplateFieldsOptionsRulesField"',
        });
    }
    const selectableLevels = val.selectableLevels == void 0
        ? void 0
        : sdIsList(val.selectableLevels)
            ? val.selectableLevels.map(function (itm) {
                if (!sdIsNumber(itm)) {
                    throw new BoxSdkError({
                        message: 'Expecting number for "MetadataTemplateFieldsOptionsRulesField"',
                    });
                }
                return itm;
            })
            : [];
    return {
        multiSelect: multiSelect,
        selectableLevels: selectableLevels,
    };
}
export function serializeMetadataTemplateFieldsField(val) {
    return {
        ['type']: serializeMetadataTemplateFieldsTypeField(val.type),
        ['key']: val.key,
        ['displayName']: val.displayName,
        ['description']: val.description,
        ['hidden']: val.hidden,
        ['options']: val.options == void 0
            ? val.options
            : val.options.map(function (item) {
                return serializeMetadataTemplateFieldsOptionsField(item);
            }),
        ['taxonomyKey']: val.taxonomyKey,
        ['taxonomyId']: val.taxonomyId,
        ['namespace']: val.namespace,
        ['optionsRules']: val.optionsRules == void 0
            ? val.optionsRules
            : serializeMetadataTemplateFieldsOptionsRulesField(val.optionsRules),
        ['id']: val.id,
    };
}
export function deserializeMetadataTemplateFieldsField(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "MetadataTemplateFieldsField"',
        });
    }
    if (val.type == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "type" of type "MetadataTemplateFieldsField" to be defined',
        });
    }
    const type = deserializeMetadataTemplateFieldsTypeField(val.type);
    if (val.key == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "key" of type "MetadataTemplateFieldsField" to be defined',
        });
    }
    if (!sdIsString(val.key)) {
        throw new BoxSdkError({
            message: 'Expecting string for "key" of type "MetadataTemplateFieldsField"',
        });
    }
    const key = val.key;
    if (val.displayName == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "displayName" of type "MetadataTemplateFieldsField" to be defined',
        });
    }
    if (!sdIsString(val.displayName)) {
        throw new BoxSdkError({
            message: 'Expecting string for "displayName" of type "MetadataTemplateFieldsField"',
        });
    }
    const displayName = val.displayName;
    if (!(val.description == void 0) && !sdIsString(val.description)) {
        throw new BoxSdkError({
            message: 'Expecting string for "description" of type "MetadataTemplateFieldsField"',
        });
    }
    const description = val.description == void 0 ? void 0 : val.description;
    if (!(val.hidden == void 0) && !sdIsBoolean(val.hidden)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "hidden" of type "MetadataTemplateFieldsField"',
        });
    }
    const hidden = val.hidden == void 0 ? void 0 : val.hidden;
    if (!(val.options == void 0) && !sdIsList(val.options)) {
        throw new BoxSdkError({
            message: 'Expecting array for "options" of type "MetadataTemplateFieldsField"',
        });
    }
    const options = val.options == void 0
        ? void 0
        : sdIsList(val.options)
            ? val.options.map(function (itm) {
                return deserializeMetadataTemplateFieldsOptionsField(itm);
            })
            : [];
    if (!(val.taxonomyKey == void 0) && !sdIsString(val.taxonomyKey)) {
        throw new BoxSdkError({
            message: 'Expecting string for "taxonomyKey" of type "MetadataTemplateFieldsField"',
        });
    }
    const taxonomyKey = val.taxonomyKey == void 0 ? void 0 : val.taxonomyKey;
    if (!(val.taxonomyId == void 0) && !sdIsString(val.taxonomyId)) {
        throw new BoxSdkError({
            message: 'Expecting string for "taxonomyId" of type "MetadataTemplateFieldsField"',
        });
    }
    const taxonomyId = val.taxonomyId == void 0 ? void 0 : val.taxonomyId;
    if (!(val.namespace == void 0) && !sdIsString(val.namespace)) {
        throw new BoxSdkError({
            message: 'Expecting string for "namespace" of type "MetadataTemplateFieldsField"',
        });
    }
    const namespace = val.namespace == void 0 ? void 0 : val.namespace;
    const optionsRules = val.optionsRules == void 0
        ? void 0
        : deserializeMetadataTemplateFieldsOptionsRulesField(val.optionsRules);
    if (!(val.id == void 0) && !sdIsString(val.id)) {
        throw new BoxSdkError({
            message: 'Expecting string for "id" of type "MetadataTemplateFieldsField"',
        });
    }
    const id = val.id == void 0 ? void 0 : val.id;
    return {
        type: type,
        key: key,
        displayName: displayName,
        description: description,
        hidden: hidden,
        options: options,
        taxonomyKey: taxonomyKey,
        taxonomyId: taxonomyId,
        namespace: namespace,
        optionsRules: optionsRules,
        id: id,
    };
}
export function serializeMetadataTemplate(val) {
    return {
        ['id']: val.id,
        ['type']: serializeMetadataTemplateTypeField(val.type),
        ['scope']: val.scope,
        ['templateKey']: val.templateKey,
        ['displayName']: val.displayName,
        ['hidden']: val.hidden,
        ['fields']: val.fields == void 0
            ? val.fields
            : val.fields.map(function (item) {
                return serializeMetadataTemplateFieldsField(item);
            }),
        ['copyInstanceOnItemCopy']: val.copyInstanceOnItemCopy,
    };
}
export function deserializeMetadataTemplate(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "MetadataTemplate"',
        });
    }
    if (val.id == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "id" of type "MetadataTemplate" to be defined',
        });
    }
    if (!sdIsString(val.id)) {
        throw new BoxSdkError({
            message: 'Expecting string for "id" of type "MetadataTemplate"',
        });
    }
    const id = val.id;
    if (val.type == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "type" of type "MetadataTemplate" to be defined',
        });
    }
    const type = deserializeMetadataTemplateTypeField(val.type);
    if (!(val.scope == void 0) && !sdIsString(val.scope)) {
        throw new BoxSdkError({
            message: 'Expecting string for "scope" of type "MetadataTemplate"',
        });
    }
    const scope = val.scope == void 0 ? void 0 : val.scope;
    if (!(val.templateKey == void 0) && !sdIsString(val.templateKey)) {
        throw new BoxSdkError({
            message: 'Expecting string for "templateKey" of type "MetadataTemplate"',
        });
    }
    const templateKey = val.templateKey == void 0 ? void 0 : val.templateKey;
    if (!(val.displayName == void 0) && !sdIsString(val.displayName)) {
        throw new BoxSdkError({
            message: 'Expecting string for "displayName" of type "MetadataTemplate"',
        });
    }
    const displayName = val.displayName == void 0 ? void 0 : val.displayName;
    if (!(val.hidden == void 0) && !sdIsBoolean(val.hidden)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "hidden" of type "MetadataTemplate"',
        });
    }
    const hidden = val.hidden == void 0 ? void 0 : val.hidden;
    if (!(val.fields == void 0) && !sdIsList(val.fields)) {
        throw new BoxSdkError({
            message: 'Expecting array for "fields" of type "MetadataTemplate"',
        });
    }
    const fields = val.fields == void 0
        ? void 0
        : sdIsList(val.fields)
            ? val.fields.map(function (itm) {
                return deserializeMetadataTemplateFieldsField(itm);
            })
            : [];
    if (!(val.copyInstanceOnItemCopy == void 0) &&
        !sdIsBoolean(val.copyInstanceOnItemCopy)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "copyInstanceOnItemCopy" of type "MetadataTemplate"',
        });
    }
    const copyInstanceOnItemCopy = val.copyInstanceOnItemCopy == void 0 ? void 0 : val.copyInstanceOnItemCopy;
    return {
        id: id,
        type: type,
        scope: scope,
        templateKey: templateKey,
        displayName: displayName,
        hidden: hidden,
        fields: fields,
        copyInstanceOnItemCopy: copyInstanceOnItemCopy,
    };
}
export function serializeMetadataTemplateInput(val) {
    return {
        ['id']: val.id,
        ['type']: val.type == void 0
            ? val.type
            : serializeMetadataTemplateTypeField(val.type),
        ['scope']: val.scope,
        ['templateKey']: val.templateKey,
        ['displayName']: val.displayName,
        ['hidden']: val.hidden,
        ['fields']: val.fields == void 0
            ? val.fields
            : val.fields.map(function (item) {
                return serializeMetadataTemplateFieldsField(item);
            }),
        ['copyInstanceOnItemCopy']: val.copyInstanceOnItemCopy,
    };
}
export function deserializeMetadataTemplateInput(val) {
    if (!sdIsMap(val)) {
        throw new BoxSdkError({
            message: 'Expecting a map for "MetadataTemplateInput"',
        });
    }
    if (val.id == void 0) {
        throw new BoxSdkError({
            message: 'Expecting "id" of type "MetadataTemplateInput" to be defined',
        });
    }
    if (!sdIsString(val.id)) {
        throw new BoxSdkError({
            message: 'Expecting string for "id" of type "MetadataTemplateInput"',
        });
    }
    const id = val.id;
    const type = val.type == void 0
        ? void 0
        : deserializeMetadataTemplateTypeField(val.type);
    if (!(val.scope == void 0) && !sdIsString(val.scope)) {
        throw new BoxSdkError({
            message: 'Expecting string for "scope" of type "MetadataTemplateInput"',
        });
    }
    const scope = val.scope == void 0 ? void 0 : val.scope;
    if (!(val.templateKey == void 0) && !sdIsString(val.templateKey)) {
        throw new BoxSdkError({
            message: 'Expecting string for "templateKey" of type "MetadataTemplateInput"',
        });
    }
    const templateKey = val.templateKey == void 0 ? void 0 : val.templateKey;
    if (!(val.displayName == void 0) && !sdIsString(val.displayName)) {
        throw new BoxSdkError({
            message: 'Expecting string for "displayName" of type "MetadataTemplateInput"',
        });
    }
    const displayName = val.displayName == void 0 ? void 0 : val.displayName;
    if (!(val.hidden == void 0) && !sdIsBoolean(val.hidden)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "hidden" of type "MetadataTemplateInput"',
        });
    }
    const hidden = val.hidden == void 0 ? void 0 : val.hidden;
    if (!(val.fields == void 0) && !sdIsList(val.fields)) {
        throw new BoxSdkError({
            message: 'Expecting array for "fields" of type "MetadataTemplateInput"',
        });
    }
    const fields = val.fields == void 0
        ? void 0
        : sdIsList(val.fields)
            ? val.fields.map(function (itm) {
                return deserializeMetadataTemplateFieldsField(itm);
            })
            : [];
    if (!(val.copyInstanceOnItemCopy == void 0) &&
        !sdIsBoolean(val.copyInstanceOnItemCopy)) {
        throw new BoxSdkError({
            message: 'Expecting boolean for "copyInstanceOnItemCopy" of type "MetadataTemplateInput"',
        });
    }
    const copyInstanceOnItemCopy = val.copyInstanceOnItemCopy == void 0 ? void 0 : val.copyInstanceOnItemCopy;
    return {
        id: id,
        type: type,
        scope: scope,
        templateKey: templateKey,
        displayName: displayName,
        hidden: hidden,
        fields: fields,
        copyInstanceOnItemCopy: copyInstanceOnItemCopy,
    };
}
//# sourceMappingURL=metadataTemplate.js.map