import { withoutDefaults } from '../util';
import { cairoDataExtensionUnsuccessfulUpdateInServer, cairoModalCtaClicked, cairoTryAgainClicked, } from '@wix/bex-utils/@wix/bi-logger-os-data/v2';
export class DataExtensionStateBIReporter {
    constructor(params) {
        this.reportArchiveFieldModalCtaClicked = (ctaName) => {
            this.reportBi(withoutDefaults(cairoModalCtaClicked)({
                ctaName,
                modalName: 'Archive custom field',
            }));
        };
        this.reportDeleteFieldModalCtaClicked = (ctaName) => {
            this.reportBi(withoutDefaults(cairoModalCtaClicked)({
                ctaName,
                modalName: 'Delete custom field',
            }));
        };
        this.reportArchiveFieldFailed = ({ origin, formValues, }) => {
            if (!formValues) {
                return;
            }
            this.reportBi(withoutDefaults(cairoDataExtensionUnsuccessfulUpdateInServer)({
                actionName: 'Archive',
                errorType: 'Technical issue',
                origin,
                permissions: this.getBiPermissions(formValues),
                fieldType: formValues.type,
                fieldName: formValues.name,
                key: formValues.key,
            }));
        };
        this.reportArchiveTryAgain = () => {
            this.reportBi(withoutDefaults(cairoTryAgainClicked)({
                actionName: 'Archive custom field',
                loaction: 'toast',
            }));
        };
        this.reportRestoreFieldFailed = ({ origin, formValues, }) => {
            if (!formValues) {
                return;
            }
            this.reportBi(withoutDefaults(cairoDataExtensionUnsuccessfulUpdateInServer)({
                actionName: 'Restore',
                errorType: 'Technical issue',
                origin,
                permissions: this.getBiPermissions(formValues),
                fieldType: formValues.type,
                fieldName: formValues.name,
                key: formValues.key,
            }));
        };
        this.reportRestoreTryAgain = () => {
            this.reportBi(withoutDefaults(cairoTryAgainClicked)({
                actionName: 'Restore custom field',
                loaction: 'toast',
            }));
        };
        const { reportBi } = params;
        this.reportBi = reportBi;
    }
    getBiPermissions(formValues) {
        const { readApps, readUsers, writeApps, writeUsers } = formValues;
        const apps = [];
        const users = [];
        if (readApps) {
            apps.push('Read');
        }
        if (writeApps) {
            apps.push('Write');
        }
        if (readUsers) {
            users.push('Read');
        }
        if (writeUsers) {
            users.push('Write');
        }
        return JSON.stringify({
            'Installed apps': apps.length !== 0 ? apps.join(' and ') : null,
            'Site visitors': users.length !== 0 ? users.join(' and ') : null,
        });
    }
}
//# sourceMappingURL=DataExtensionStateBIReporter.js.map