"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskAssignmentsManager = exports.DeleteTaskAssignmentByIdHeaders = exports.UpdateTaskAssignmentByIdHeaders = exports.GetTaskAssignmentByIdHeaders = exports.CreateTaskAssignmentHeaders = exports.CreateTaskAssignmentRequestBodyTaskField = exports.GetTaskAssignmentsHeaders = exports.DeleteTaskAssignmentByIdOptionals = exports.UpdateTaskAssignmentByIdOptionals = exports.GetTaskAssignmentByIdOptionals = exports.CreateTaskAssignmentOptionals = exports.GetTaskAssignmentsOptionals = void 0;
exports.serializeCreateTaskAssignmentRequestBodyTaskTypeField = serializeCreateTaskAssignmentRequestBodyTaskTypeField;
exports.deserializeCreateTaskAssignmentRequestBodyTaskTypeField = deserializeCreateTaskAssignmentRequestBodyTaskTypeField;
exports.serializeCreateTaskAssignmentRequestBodyTaskField = serializeCreateTaskAssignmentRequestBodyTaskField;
exports.deserializeCreateTaskAssignmentRequestBodyTaskField = deserializeCreateTaskAssignmentRequestBodyTaskField;
exports.serializeCreateTaskAssignmentRequestBodyTaskFieldInput = serializeCreateTaskAssignmentRequestBodyTaskFieldInput;
exports.deserializeCreateTaskAssignmentRequestBodyTaskFieldInput = deserializeCreateTaskAssignmentRequestBodyTaskFieldInput;
exports.serializeCreateTaskAssignmentRequestBodyAssignToField = serializeCreateTaskAssignmentRequestBodyAssignToField;
exports.deserializeCreateTaskAssignmentRequestBodyAssignToField = deserializeCreateTaskAssignmentRequestBodyAssignToField;
exports.serializeCreateTaskAssignmentRequestBody = serializeCreateTaskAssignmentRequestBody;
exports.deserializeCreateTaskAssignmentRequestBody = deserializeCreateTaskAssignmentRequestBody;
exports.serializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField = serializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField;
exports.deserializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField = deserializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField;
exports.serializeUpdateTaskAssignmentByIdRequestBody = serializeUpdateTaskAssignmentByIdRequestBody;
exports.deserializeUpdateTaskAssignmentByIdRequestBody = deserializeUpdateTaskAssignmentByIdRequestBody;
const taskAssignments_1 = require("../schemas/taskAssignments");
const taskAssignment_1 = require("../schemas/taskAssignment");
const errors_1 = require("../box/errors");
const network_1 = require("../networking/network");
const fetchOptions_1 = require("../networking/fetchOptions");
const utils_1 = require("../internal/utils");
const utils_2 = require("../internal/utils");
const json_1 = require("../serialization/json");
const json_2 = require("../serialization/json");
class GetTaskAssignmentsOptionals {
    headers = new GetTaskAssignmentsHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetTaskAssignmentsOptionals = GetTaskAssignmentsOptionals;
class CreateTaskAssignmentOptionals {
    headers = new CreateTaskAssignmentHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.CreateTaskAssignmentOptionals = CreateTaskAssignmentOptionals;
class GetTaskAssignmentByIdOptionals {
    headers = new GetTaskAssignmentByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.GetTaskAssignmentByIdOptionals = GetTaskAssignmentByIdOptionals;
class UpdateTaskAssignmentByIdOptionals {
    requestBody = {};
    headers = new UpdateTaskAssignmentByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.requestBody !== undefined) {
            this.requestBody = fields.requestBody;
        }
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.UpdateTaskAssignmentByIdOptionals = UpdateTaskAssignmentByIdOptionals;
class DeleteTaskAssignmentByIdOptionals {
    headers = new DeleteTaskAssignmentByIdHeaders({});
    cancellationToken = void 0;
    constructor(fields) {
        if (fields.headers !== undefined) {
            this.headers = fields.headers;
        }
        if (fields.cancellationToken !== undefined) {
            this.cancellationToken = fields.cancellationToken;
        }
    }
}
exports.DeleteTaskAssignmentByIdOptionals = DeleteTaskAssignmentByIdOptionals;
class GetTaskAssignmentsHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetTaskAssignmentsHeaders = GetTaskAssignmentsHeaders;
class CreateTaskAssignmentRequestBodyTaskField {
    /**
     * The ID of the task. */
    id;
    /**
     * The type of the item to assign. */
    type = 'task';
    rawData;
    constructor(fields) {
        if (fields.id !== undefined) {
            this.id = fields.id;
        }
        if (fields.type !== undefined) {
            this.type = fields.type;
        }
        if (fields.rawData !== undefined) {
            this.rawData = fields.rawData;
        }
    }
}
exports.CreateTaskAssignmentRequestBodyTaskField = CreateTaskAssignmentRequestBodyTaskField;
class CreateTaskAssignmentHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.CreateTaskAssignmentHeaders = CreateTaskAssignmentHeaders;
class GetTaskAssignmentByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.GetTaskAssignmentByIdHeaders = GetTaskAssignmentByIdHeaders;
class UpdateTaskAssignmentByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.UpdateTaskAssignmentByIdHeaders = UpdateTaskAssignmentByIdHeaders;
class DeleteTaskAssignmentByIdHeaders {
    /**
     * Extra headers that will be included in the HTTP request. */
    extraHeaders = {};
    constructor(fields) {
        if (fields.extraHeaders !== undefined) {
            this.extraHeaders = fields.extraHeaders;
        }
    }
}
exports.DeleteTaskAssignmentByIdHeaders = DeleteTaskAssignmentByIdHeaders;
class TaskAssignmentsManager {
    auth;
    networkSession = new network_1.NetworkSession({});
    constructor(fields) {
        if (fields.auth !== undefined) {
            this.auth = fields.auth;
        }
        if (fields.networkSession !== undefined) {
            this.networkSession = fields.networkSession;
        }
    }
    /**
       * Lists all of the assignments for a given task.
       * @param {string} taskId The ID of the task.
      Example: "12345"
       * @param {GetTaskAssignmentsOptionalsInput} optionalsInput
       * @returns {Promise<TaskAssignments>}
       */
    async getTaskAssignments(taskId, optionalsInput = {}) {
        const optionals = new GetTaskAssignmentsOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/tasks/', (0, utils_2.toString)(taskId), '/assignments'),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, taskAssignments_1.deserializeTaskAssignments)(response.data),
            rawData: response.data,
        };
    }
    /**
     * Assigns a task to a user.
     *
     * A task can be assigned to more than one user by creating multiple
     * assignments.
     * @param {CreateTaskAssignmentRequestBody} requestBody Request body of createTaskAssignment method
     * @param {CreateTaskAssignmentOptionalsInput} optionalsInput
     * @returns {Promise<TaskAssignment>}
     */
    async createTaskAssignment(requestBody, optionalsInput = {}) {
        const optionals = new CreateTaskAssignmentOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/task_assignments'),
            method: 'POST',
            headers: headersMap,
            data: serializeCreateTaskAssignmentRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, taskAssignment_1.deserializeTaskAssignment)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Retrieves information about a task assignment.
       * @param {string} taskAssignmentId The ID of the task assignment.
      Example: "12345"
       * @param {GetTaskAssignmentByIdOptionalsInput} optionalsInput
       * @returns {Promise<TaskAssignment>}
       */
    async getTaskAssignmentById(taskAssignmentId, optionalsInput = {}) {
        const optionals = new GetTaskAssignmentByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/task_assignments/', (0, utils_2.toString)(taskAssignmentId)),
            method: 'GET',
            headers: headersMap,
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, taskAssignment_1.deserializeTaskAssignment)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Updates a task assignment. This endpoint can be
       * used to update the state of a task assigned to a user.
       * @param {string} taskAssignmentId The ID of the task assignment.
      Example: "12345"
       * @param {UpdateTaskAssignmentByIdOptionalsInput} optionalsInput
       * @returns {Promise<TaskAssignment>}
       */
    async updateTaskAssignmentById(taskAssignmentId, optionalsInput = {}) {
        const optionals = new UpdateTaskAssignmentByIdOptionals({
            requestBody: optionalsInput.requestBody,
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const requestBody = optionals.requestBody;
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/task_assignments/', (0, utils_2.toString)(taskAssignmentId)),
            method: 'PUT',
            headers: headersMap,
            data: serializeUpdateTaskAssignmentByIdRequestBody(requestBody),
            contentType: 'application/json',
            responseFormat: 'json',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return {
            ...(0, taskAssignment_1.deserializeTaskAssignment)(response.data),
            rawData: response.data,
        };
    }
    /**
       * Deletes a specific task assignment.
       * @param {string} taskAssignmentId The ID of the task assignment.
      Example: "12345"
       * @param {DeleteTaskAssignmentByIdOptionalsInput} optionalsInput
       * @returns {Promise<undefined>}
       */
    async deleteTaskAssignmentById(taskAssignmentId, optionalsInput = {}) {
        const optionals = new DeleteTaskAssignmentByIdOptionals({
            headers: optionalsInput.headers,
            cancellationToken: optionalsInput.cancellationToken,
        });
        const headers = optionals.headers;
        const cancellationToken = optionals.cancellationToken;
        const headersMap = (0, utils_1.prepareParams)({ ...{}, ...headers.extraHeaders });
        const response = await this.networkSession.networkClient.fetch(new fetchOptions_1.FetchOptions({
            url: ''.concat(this.networkSession.baseUrls.baseUrl, '/2.0/task_assignments/', (0, utils_2.toString)(taskAssignmentId)),
            method: 'DELETE',
            headers: headersMap,
            responseFormat: 'no_content',
            auth: this.auth,
            networkSession: this.networkSession,
            cancellationToken: cancellationToken,
        }));
        return void 0;
    }
}
exports.TaskAssignmentsManager = TaskAssignmentsManager;
function serializeCreateTaskAssignmentRequestBodyTaskTypeField(val) {
    return val;
}
function deserializeCreateTaskAssignmentRequestBodyTaskTypeField(val) {
    if (val == 'task') {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize CreateTaskAssignmentRequestBodyTaskTypeField",
    });
}
function serializeCreateTaskAssignmentRequestBodyTaskField(val) {
    return {
        ['id']: val.id,
        ['type']: serializeCreateTaskAssignmentRequestBodyTaskTypeField(val.type),
    };
}
function deserializeCreateTaskAssignmentRequestBodyTaskField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateTaskAssignmentRequestBodyTaskField"',
        });
    }
    if (val.id == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "id" of type "CreateTaskAssignmentRequestBodyTaskField" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "CreateTaskAssignmentRequestBodyTaskField"',
        });
    }
    const id = val.id;
    if (val.type == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "type" of type "CreateTaskAssignmentRequestBodyTaskField" to be defined',
        });
    }
    const type = deserializeCreateTaskAssignmentRequestBodyTaskTypeField(val.type);
    return {
        id: id,
        type: type,
    };
}
function serializeCreateTaskAssignmentRequestBodyTaskFieldInput(val) {
    return {
        ['id']: val.id,
        ['type']: val.type == void 0
            ? val.type
            : serializeCreateTaskAssignmentRequestBodyTaskTypeField(val.type),
    };
}
function deserializeCreateTaskAssignmentRequestBodyTaskFieldInput(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateTaskAssignmentRequestBodyTaskFieldInput"',
        });
    }
    if (val.id == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "id" of type "CreateTaskAssignmentRequestBodyTaskFieldInput" to be defined',
        });
    }
    if (!(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "CreateTaskAssignmentRequestBodyTaskFieldInput"',
        });
    }
    const id = val.id;
    const type = val.type == void 0
        ? void 0
        : deserializeCreateTaskAssignmentRequestBodyTaskTypeField(val.type);
    return {
        id: id,
        type: type,
    };
}
function serializeCreateTaskAssignmentRequestBodyAssignToField(val) {
    return { ['id']: val.id, ['login']: val.login };
}
function deserializeCreateTaskAssignmentRequestBodyAssignToField(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateTaskAssignmentRequestBodyAssignToField"',
        });
    }
    if (!(val.id == void 0) && !(0, json_1.sdIsString)(val.id)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "id" of type "CreateTaskAssignmentRequestBodyAssignToField"',
        });
    }
    const id = val.id == void 0 ? void 0 : val.id;
    if (!(val.login == void 0) && !(0, json_1.sdIsString)(val.login)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "login" of type "CreateTaskAssignmentRequestBodyAssignToField"',
        });
    }
    const login = val.login == void 0 ? void 0 : val.login;
    return {
        id: id,
        login: login,
    };
}
function serializeCreateTaskAssignmentRequestBody(val) {
    return {
        ['task']: serializeCreateTaskAssignmentRequestBodyTaskField(val.task),
        ['assign_to']: serializeCreateTaskAssignmentRequestBodyAssignToField(val.assignTo),
    };
}
function deserializeCreateTaskAssignmentRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "CreateTaskAssignmentRequestBody"',
        });
    }
    if (val.task == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "task" of type "CreateTaskAssignmentRequestBody" to be defined',
        });
    }
    const task = deserializeCreateTaskAssignmentRequestBodyTaskField(val.task);
    if (val.assign_to == void 0) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting "assign_to" of type "CreateTaskAssignmentRequestBody" to be defined',
        });
    }
    const assignTo = deserializeCreateTaskAssignmentRequestBodyAssignToField(val.assign_to);
    return {
        task: task,
        assignTo: assignTo,
    };
}
function serializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField(val) {
    return val;
}
function deserializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField(val) {
    if (val == 'completed') {
        return val;
    }
    if (val == 'incomplete') {
        return val;
    }
    if (val == 'approved') {
        return val;
    }
    if (val == 'rejected') {
        return val;
    }
    if ((0, json_1.sdIsString)(val)) {
        return val;
    }
    throw new errors_1.BoxSdkError({
        message: "Can't deserialize UpdateTaskAssignmentByIdRequestBodyResolutionStateField",
    });
}
function serializeUpdateTaskAssignmentByIdRequestBody(val) {
    return {
        ['message']: val.message,
        ['resolution_state']: val.resolutionState == void 0
            ? val.resolutionState
            : serializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField(val.resolutionState),
    };
}
function deserializeUpdateTaskAssignmentByIdRequestBody(val) {
    if (!(0, json_2.sdIsMap)(val)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting a map for "UpdateTaskAssignmentByIdRequestBody"',
        });
    }
    if (!(val.message == void 0) && !(0, json_1.sdIsString)(val.message)) {
        throw new errors_1.BoxSdkError({
            message: 'Expecting string for "message" of type "UpdateTaskAssignmentByIdRequestBody"',
        });
    }
    const message = val.message == void 0 ? void 0 : val.message;
    const resolutionState = val.resolution_state == void 0
        ? void 0
        : deserializeUpdateTaskAssignmentByIdRequestBodyResolutionStateField(val.resolution_state);
    return {
        message: message,
        resolutionState: resolutionState,
    };
}
//# sourceMappingURL=taskAssignments.js.map