import LoggingUtils from "@impl/utils/LoggingUtils";
import { ConsoleColor } from "@business-logic/types/Enums";
import TestCase from "@business-logic/types/TestCase";

// File with interfaces/classes related to Disposable

export interface IDisposable {
    disposeAll(): void;
    setupAll(): void;
}

export abstract class DisposableBase implements IDisposable {
    protected abstract setup(): Promise<void>;
    protected abstract dispose(): Promise<void>;

    public async setupAll(): Promise<void> {
        if (!TestCase.FrameworkConfig.destroyResources) {
            LoggingUtils.log(TestCase.Constants.CREATION_HALTED, ConsoleColor.Yellow);
            return;
        }
        await this.setup();
    }

    public async disposeAll(): Promise<void> {
        if (!TestCase.FrameworkConfig.destroyResources || !TestCase.FrameworkConfig.createResources) {
            LoggingUtils.log(TestCase.Constants.DISPOSE_HALTED, ConsoleColor.Yellow);
            return;
        }
        await this.dispose();
    }
}