"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeGroupMembershipsOrderDirectionField = serializeGroupMembershipsOrderDirectionField;
exports.deserializeGroupMembershipsOrderDirectionField = deserializeGroupMembershipsOrderDirectionField;
exports.serializeGroupMembershipsOrderField = serializeGroupMembershipsOrderField;
exports.deserializeGroupMembershipsOrderField = deserializeGroupMembershipsOrderField;
exports.serializeGroupMemberships = serializeGroupMemberships;
exports.deserializeGroupMemberships = deserializeGroupMemberships;
const groupMembership_1 = require("./groupMembership");
const groupMembership_2 = require("./groupMembership");
const errors_1 = require("../box/errors");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
const json_3 = require("../serialization/json");
const json_4 = require("../serialization/json");
function serializeGroupMembershipsOrderDirectionField(val) {
    return val;
}
function deserializeGroupMembershipsOrderDirectionField(val) {
    if (val == 'ASC') {
        return val;
    }
    if (val == 'DESC') {
        return val;
    }
    if ((0, json_2.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize GroupMembershipsOrderDirectionField",
    });
}
function serializeGroupMembershipsOrderField(val) {
    return {
        ['by']: val.by,
        ['direction']: val.direction == void 0
            ? val.direction
            : serializeGroupMembershipsOrderDirectionField(val.direction),
    };
}
function deserializeGroupMembershipsOrderField(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "GroupMembershipsOrderField"',
        });
    }
    if (!(val.by == void 0) && !(0, json_2.sdIsString)(val.by)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "by" of type "GroupMembershipsOrderField"',
        });
    }
    const by = val.by == void 0 ? void 0 : val.by;
    const direction = val.direction == void 0
        ? void 0
        : deserializeGroupMembershipsOrderDirectionField(val.direction);
    return { by: by, direction: direction };
}
function serializeGroupMemberships(val) {
    return {
        ['total_count']: val.totalCount,
        ['limit']: val.limit,
        ['offset']: val.offset,
        ['order']: val.order == void 0
            ? val.order
            : val.order.map(function (item) {
                return serializeGroupMembershipsOrderField(item);
            }),
        ['entries']: val.entries == void 0
            ? val.entries
            : val.entries.map(function (item) {
                return (0, groupMembership_1.serializeGroupMembership)(item);
            }),
    };
}
function deserializeGroupMemberships(val) {
    if (!(0, json_4.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "GroupMemberships"',
        });
    }
    if (!(val.total_count == void 0) && !(0, json_1.sdIsNumber)(val.total_count)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting number for "total_count" of type "GroupMemberships"',
        });
    }
    const totalCount = val.total_count == void 0 ? void 0 : val.total_count;
    if (!(val.limit == void 0) && !(0, json_1.sdIsNumber)(val.limit)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting number for "limit" of type "GroupMemberships"',
        });
    }
    const limit = val.limit == void 0 ? void 0 : val.limit;
    if (!(val.offset == void 0) && !(0, json_1.sdIsNumber)(val.offset)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting number for "offset" of type "GroupMemberships"',
        });
    }
    const offset = val.offset == void 0 ? void 0 : val.offset;
    if (!(val.order == void 0) && !(0, json_3.sdIsList)(val.order)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting array for "order" of type "GroupMemberships"',
        });
    }
    const order = val.order == void 0
        ? void 0
        : (0, json_3.sdIsList)(val.order)
            ? val.order.map(function (itm) {
                return deserializeGroupMembershipsOrderField(itm);
            })
            : [];
    if (!(val.entries == void 0) && !(0, json_3.sdIsList)(val.entries)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting array for "entries" of type "GroupMemberships"',
        });
    }
    const entries = val.entries == void 0
        ? void 0
        : (0, json_3.sdIsList)(val.entries)
            ? val.entries.map(function (itm) {
                return (0, groupMembership_2.deserializeGroupMembership)(itm);
            })
            : [];
    return {
        totalCount: totalCount,
        limit: limit,
        offset: offset,
        order: order,
        entries: entries,
    };
}
//# sourceMappingURL=groupMemberships.js.map