"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 lodash_1 = __importDefault(require("lodash"));
const accountHelper_1 = require("../../complex/accountHelper");
const resource_1 = __importDefault(require("../base/resource"));
class Account extends resource_1.default {
    constructor(id, clientSession, parentApi) {
        super(clientSession, 'awsAccounts', id, parentApi);
    }
    async cleanup() {
        const accountHelper = new accountHelper_1.AccountHelper();
        const settings = this._setup.getSettings();
        const existingAccounts = await accountHelper.listOnboardedAccounts();
        const resource = lodash_1.default.find(existingAccounts, { awsAccountId: settings.get('awsAccountId') });
        if (resource) {
            const { id, awsAccountId } = resource;
            await accountHelper.deOnboardAccount(awsAccountId);
            await accountHelper.deleteDdbRecords(id, awsAccountId);
        }
    }
}
exports.default = Account;
//# sourceMappingURL=account.js.map