/*
 *                                      Copyright 2025 WebPros International, LLC
 *                                                           All rights reserved.
 * copyright@cpanel.net                                         http://cpanel.net
 * This code is subject to the cPanel license. Unauthorized copying is prohibited.
 */

import { NVData } from "@classes/nvdata";
import { CpanelConfig } from "@classes/config_file/cpanelconfig";
import { TeamUser } from "@classes/account/team_user";
import { CpanelServiceAccount } from "@page/cpanel/cpanel";

/**
 * This class holds Sitejet banner logic that is needed/used independlty
 * of a corresponding Page object
 *
 */
export class SitejetBannerAIClass {
    /** cPanel account object*/
    account: CpanelServiceAccount | TeamUser;
    /** NVData object*/
    nvdata: NVData;
    /** CpaneConfig object*/
    cpanelconfig: CpanelConfig;

    constructor(account: CpanelServiceAccount | TeamUser) {
        this.account = account;
        this.nvdata = new NVData();
        this.cpanelconfig = new CpanelConfig(account.ssh);
    }

    /*
     * Function that resets the banner NVData file and the cPanel Config in
     * order that the banner is displayed once again
     *
     * The NVdata file that is created when the banner is dismissed is
     *   /home/<CPUSER>/.cpanel/nvdata/cp-feature-showcase_dismissed
     * and the contents of this file are simply the value 1.
     * In order to get the banner back, set the file contents to 0.
     */
    async resetBannerSettings(): Promise<void> {
        await this.nvdata.setNVData(this.account, {
            "cp-feature-showcase_dismissed": 0,
        });
        await this.cpanelconfig.set({ display_cpanel_promotions: "1" });
    }
}
