"use strict";
/*
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Twilio - Iam
 * This is the public Twilio REST API.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuthAppInstance = exports.OAuthAppContextImpl = exports.IamV1OrganizationVendoroauthappPolicy = exports.IamV1OrganizationVendorOauthAppUpdateRequestPolicy = exports.IamV1AccountVendorOauthAppUpdateRequest = exports.IamV1AccountVendorOauthAppCreateRequest = void 0;
exports.OAuthAppListInstance = OAuthAppListInstance;
const util_1 = require("util");
const deserialize = require("../../../base/deserialize");
const serialize = require("../../../base/serialize");
const utility_1 = require("../../../base/utility");
class IamV1AccountVendorOauthAppCreateRequest {
}
exports.IamV1AccountVendorOauthAppCreateRequest = IamV1AccountVendorOauthAppCreateRequest;
class IamV1AccountVendorOauthAppUpdateRequest {
}
exports.IamV1AccountVendorOauthAppUpdateRequest = IamV1AccountVendorOauthAppUpdateRequest;
class IamV1OrganizationVendorOauthAppUpdateRequestPolicy {
}
exports.IamV1OrganizationVendorOauthAppUpdateRequestPolicy = IamV1OrganizationVendorOauthAppUpdateRequestPolicy;
class IamV1OrganizationVendoroauthappPolicy {
}
exports.IamV1OrganizationVendoroauthappPolicy = IamV1OrganizationVendoroauthappPolicy;
class OAuthAppContextImpl {
    constructor(_version, sid) {
        this._version = _version;
        if (!(0, utility_1.isValidPathParam)(sid)) {
            throw new Error("Parameter 'sid' is not valid.");
        }
        this._solution = { sid };
        this._uri = `/Account/OAuthApps/${sid}`;
    }
    remove(callback) {
        const headers = {};
        const instance = this;
        let operationVersion = instance._version, operationPromise = operationVersion.remove({
            uri: instance._uri,
            method: "delete",
            headers,
        });
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    }
    removeWithHttpInfo(callback) {
        const headers = {};
        const instance = this;
        let operationVersion = instance._version;
        // DELETE operation - returns boolean based on status code
        let operationPromise = operationVersion
            .removeWithResponseInfo({ uri: instance._uri, method: "delete", headers })
            .then((response) => ({
            ...response,
            body: response.statusCode === 204,
        }));
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    }
    update(params, headers, callback) {
        if (params === null || params === undefined) {
            throw new Error('Required parameter "params" missing.');
        }
        let data = {};
        data = params;
        if (headers === null || headers === undefined) {
            headers = {};
        }
        headers["Content-Type"] = "application/json";
        headers["Accept"] = "application/json";
        const instance = this;
        let operationVersion = instance._version, operationPromise = operationVersion.update({
            uri: instance._uri,
            method: "put",
            data,
            headers,
        });
        operationPromise = operationPromise.then((payload) => new OAuthAppInstance(operationVersion, payload, instance._solution.sid));
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    }
    updateWithHttpInfo(params, headers, callback) {
        if (params === null || params === undefined) {
            throw new Error('Required parameter "params" missing.');
        }
        let data = {};
        data = params;
        if (headers === null || headers === undefined) {
            headers = {};
        }
        headers["Content-Type"] = "application/json";
        headers["Accept"] = "application/json";
        const instance = this;
        let operationVersion = instance._version;
        // CREATE, FETCH, UPDATE operations
        let operationPromise = operationVersion
            .updateWithResponseInfo({
            uri: instance._uri,
            method: "put",
            data,
            headers,
        })
            .then((response) => ({
            ...response,
            body: new OAuthAppInstance(operationVersion, response.body, instance._solution.sid),
        }));
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    }
    /**
     * Provide a user-friendly representation
     *
     * @returns Object
     */
    toJSON() {
        return this._solution;
    }
    [util_1.inspect.custom](_depth, options) {
        return (0, util_1.inspect)(this.toJSON(), options);
    }
}
exports.OAuthAppContextImpl = OAuthAppContextImpl;
class OAuthAppInstance {
    constructor(_version, payload, sid) {
        this._version = _version;
        this.type = payload.type;
        this.sid = payload.sid;
        this.friendlyName = payload.friendly_name;
        this.description = payload.description;
        this.dateCreated = deserialize.iso8601DateTime(payload.date_created);
        this.createdBy = payload.created_by;
        this.secret = payload.secret;
        this.status = payload.status;
        this.policy = payload.policy;
        this.accessTokenTtl = deserialize.integer(payload.access_token_ttl);
        this.code = payload.code;
        this.message = payload.message;
        this.moreInfo = payload.more_info;
        this._solution = { sid: sid || this.sid };
    }
    get _proxy() {
        this._context =
            this._context ||
                new OAuthAppContextImpl(this._version, this._solution.sid);
        return this._context;
    }
    /**
     * Remove a OAuthAppInstance
     *
     * @param callback - Callback to handle processed record
     *
     * @returns Resolves to processed boolean
     */
    remove(callback) {
        return this._proxy.remove(callback);
    }
    /**
     * Remove a OAuthAppInstance and return HTTP info
     *
     * @param callback - Callback to handle processed record
     *
     * @returns Resolves to processed boolean with HTTP metadata
     */
    removeWithHttpInfo(callback) {
        return this._proxy.removeWithHttpInfo(callback);
    }
    update(params, callback) {
        return this._proxy.update(params, callback);
    }
    updateWithHttpInfo(params, callback) {
        return this._proxy.updateWithHttpInfo(params, callback);
    }
    /**
     * Provide a user-friendly representation
     *
     * @returns Object
     */
    toJSON() {
        return {
            type: this.type,
            sid: this.sid,
            friendlyName: this.friendlyName,
            description: this.description,
            dateCreated: this.dateCreated,
            createdBy: this.createdBy,
            secret: this.secret,
            status: this.status,
            policy: this.policy,
            accessTokenTtl: this.accessTokenTtl,
            code: this.code,
            message: this.message,
            moreInfo: this.moreInfo,
        };
    }
    [util_1.inspect.custom](_depth, options) {
        return (0, util_1.inspect)(this.toJSON(), options);
    }
}
exports.OAuthAppInstance = OAuthAppInstance;
function OAuthAppListInstance(version) {
    const instance = ((sid) => instance.get(sid));
    instance.get = function get(sid) {
        return new OAuthAppContextImpl(version, sid);
    };
    instance._version = version;
    instance._solution = {};
    instance._uri = `/Account/OAuthApps`;
    instance.create = function create(params, headers, callback) {
        if (params === null || params === undefined) {
            throw new Error('Required parameter "params" missing.');
        }
        let data = {};
        data = params;
        if (headers === null || headers === undefined) {
            headers = {};
        }
        headers["Content-Type"] = "application/json";
        headers["Accept"] = "application/json";
        let operationVersion = version, operationPromise = operationVersion.create({
            uri: instance._uri,
            method: "post",
            data,
            headers,
        });
        operationPromise = operationPromise.then((payload) => new OAuthAppInstance(operationVersion, payload));
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    };
    instance.createWithHttpInfo = function createWithHttpInfo(params, headers, callback) {
        if (params === null || params === undefined) {
            throw new Error('Required parameter "params" missing.');
        }
        let data = {};
        data = params;
        if (headers === null || headers === undefined) {
            headers = {};
        }
        headers["Content-Type"] = "application/json";
        headers["Accept"] = "application/json";
        let operationVersion = version;
        // CREATE, FETCH, UPDATE operations
        let operationPromise = operationVersion
            .createWithResponseInfo({
            uri: instance._uri,
            method: "post",
            data,
            headers,
        })
            .then((response) => ({
            ...response,
            body: new OAuthAppInstance(operationVersion, response.body),
        }));
        operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
        return operationPromise;
    };
    instance.toJSON = function toJSON() {
        return instance._solution;
    };
    instance[util_1.inspect.custom] = function inspectImpl(_depth, options) {
        return (0, util_1.inspect)(instance.toJSON(), options);
    };
    return instance;
}
