"use strict";
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../utils/constants");
const utilities_1 = require("../../utils/utilities");
const resource_1 = __importDefault(require("../base/resource"));
class CostCenter extends resource_1.default {
    constructor(id, clientSession, parentApi) {
        super(clientSession, 'costCenters', id, parentApi);
    }
    async cleanup() {
        const defAdminSession = await this._setup.getDefaultAdminSession();
        await (0, utilities_1.sleep)(constants_1.DEFLAKE_DELAY_IN_MILLISECONDS); //Avoid throttling when terminating multiple cost centers
        await defAdminSession.resources.costCenters
            .costCenter(this._id)
            .delete()
            .then()
            .catch(async (error) => {
            // Adding one retry in case deletion of dependency i.e. Project has eventual consistency issues
            console.error('Error occurred when trying to delete CostCenter', error);
            console.error(`Attempting retry after ${constants_1.DEFLAKE_DELAY_IN_MILLISECONDS} ms`);
            await (0, utilities_1.sleep)(constants_1.DEFLAKE_DELAY_IN_MILLISECONDS);
            await defAdminSession.resources.costCenters.costCenter(this._id).delete().then();
        });
    }
}
exports.default = CostCenter;
//# sourceMappingURL=costCenter.js.map