"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyServiceAccountAbilities = void 0;
const types_1 = require("../ee/serviceAccounts/types");
const projects_1 = require("../types/projects");
const applyServiceAccountStaticAbilities = {
    [types_1.ServiceAccountScope.ORG_READ]: ({ organizationUuid, builder: { can }, }) => {
        can('view', 'OrganizationMemberProfile', {
            organizationUuid,
        });
        can('view', 'JobStatus', {
        // createdByUserUuid: userUuid,
        });
        can('view', 'PinnedItems', {
            organizationUuid,
        });
        can('view', 'Dashboard', {
            organizationUuid,
            inheritsFromOrgOrProject: true,
        });
        can('view', 'SavedChart', {
            organizationUuid,
            inheritsFromOrgOrProject: true,
        });
        can('view', 'Dashboard', {
            organizationUuid,
            /* access: {
                $elemMatch: { userUuid: userUuid },
            }, */
        });
        can('view', 'SavedChart', {
            organizationUuid,
            /*
           access: {
                $elemMatch: { userUuid: userUuid },
            }, */
        });
        can('view', 'Space', {
            organizationUuid,
            inheritsFromOrgOrProject: true,
        });
        can('view', 'Space', {
            organizationUuid,
            /* access: {
                $elemMatch: { userUuid: userUuid },
            }, */
        });
        can('view', 'Project', {
            organizationUuid,
        });
        can('view', 'Organization', {
            organizationUuid,
        });
        can('manage', 'ExportCsv', {
            organizationUuid,
        });
        can('view', 'DashboardComments', {
            organizationUuid,
        });
        can('view', 'Tags', {
            organizationUuid,
        });
        can('view', 'MetricsTree', {
            organizationUuid,
        });
        can('view', 'SpotlightTableConfig', {
            organizationUuid,
        });
        can('view', 'AiAgentThread', {
            organizationUuid,
            // userUuid: userUuid,
        });
        can('create', 'Job');
        can('view', 'Job');
        can('view', 'UnderlyingData', {
            organizationUuid,
        });
        can('view', 'SemanticViewer', {
            organizationUuid,
        });
        can('manage', 'ChangeCsvResults', {
            organizationUuid,
        });
        can('manage', 'Explore', {
            organizationUuid,
        });
        can('create', 'ScheduledDeliveries', {
            organizationUuid,
        });
        can('create', 'DashboardComments', {
            organizationUuid,
        });
        can('manage', 'Dashboard', {
            organizationUuid,
            /*  access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.EDITOR,
                },
            }, */
        });
        can('manage', 'SavedChart', {
            organizationUuid,
            /* access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.EDITOR,
                },
            }, */
        });
        can('manage', 'SemanticViewer', {
            organizationUuid,
            /*  access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.EDITOR,
                },
            }, */
        });
        can('manage', 'Dashboard', {
            organizationUuid,
            /* access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.ADMIN,
                },
            }, */
        });
        can('manage', 'SavedChart', {
            organizationUuid,
            /* access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.ADMIN,
                },
            }, */
        });
        can('manage', 'Space', {
            organizationUuid,
            /*  access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.ADMIN,
                },
            }, */
        });
        can('view', 'AiAgent', {
            organizationUuid,
        });
        can('create', 'AiAgentThread', {
            organizationUuid,
        });
    },
    [types_1.ServiceAccountScope.ORG_EDIT]: ({ organizationUuid, builder: { can }, }) => {
        applyServiceAccountStaticAbilities[types_1.ServiceAccountScope.ORG_READ]({
            organizationUuid,
            builder: { can },
        });
        can('manage', 'Space', {
            organizationUuid,
            inheritsFromOrgOrProject: true,
        });
        can('create', 'Space', {
            organizationUuid,
        });
        can('manage', 'Job');
        can('manage', 'PinnedItems', {
            organizationUuid,
        });
        can('manage', 'ScheduledDeliveries', {
            organizationUuid,
        });
        can('manage', 'DashboardComments', {
            organizationUuid,
        });
        can('manage', 'SemanticViewer', {
            organizationUuid,
        });
        can('manage', 'Tags', {
            organizationUuid,
        });
        can('manage', 'MetricsTree', {
            organizationUuid,
        });
    },
    [types_1.ServiceAccountScope.ORG_ADMIN]: ({ organizationUuid, builder: { can }, }) => {
        applyServiceAccountStaticAbilities[types_1.ServiceAccountScope.ORG_EDIT]({
            organizationUuid,
            builder: { can },
        });
        can('manage', 'PreAggregation', {
            organizationUuid,
        });
        can('manage', 'VirtualView', {
            organizationUuid,
        });
        can('manage', 'CustomSql', {
            organizationUuid,
        });
        can('manage', 'CustomFields', {
            organizationUuid,
        });
        can('manage', 'SqlRunner', {
            organizationUuid,
        });
        can('manage', 'Validation', {
            organizationUuid,
        });
        can('promote', 'SavedChart', {
            organizationUuid,
            /* access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.EDITOR,
                },
            }, */
        });
        can('promote', 'Dashboard', {
            organizationUuid,
            /* access: {
                $elemMatch: {
                    userUuid: userUuid,
                    role: SpaceMemberRole.EDITOR,
                },
            }, */
        });
        can('manage', 'CompileProject', {
            organizationUuid,
        });
        can('create', 'Project', {
            organizationUuid,
            type: projects_1.ProjectType.PREVIEW,
        });
        can('manage', 'DeployProject', {
            organizationUuid,
        });
        can('update', 'Project', {
            organizationUuid,
        });
        can('delete', 'Project', {
            organizationUuid,
            type: projects_1.ProjectType.PREVIEW,
        });
        can('manage', 'SpotlightTableConfig', {
            organizationUuid,
        });
        can('manage', 'ContentAsCode', {
            organizationUuid,
        });
        can('manage', 'ContentVerification', {
            organizationUuid,
        });
        can('view', 'JobStatus', {
            organizationUuid,
        });
        can('manage', 'AiAgent', {
            organizationUuid,
        });
        can('manage', 'AiAgentThread', {
            organizationUuid,
            //  userUuid: userUuid,
        });
        can('manage', 'DataApp', {
            organizationUuid,
        });
        can('manage', 'Dashboard', {
            organizationUuid,
        });
        can('manage', 'Space', {
            organizationUuid,
        });
        can('manage', 'SavedChart', {
            organizationUuid,
        });
        can('create', 'Project', {
            organizationUuid,
            type: { $in: [projects_1.ProjectType.DEFAULT, projects_1.ProjectType.PREVIEW] },
        });
        can('delete', 'Project', {
            organizationUuid,
        });
        can('manage', 'Project', {
            organizationUuid,
        });
        can('manage', 'InviteLink', {
            organizationUuid,
        });
        can('manage', 'Organization', {
            organizationUuid,
        });
        can('view', 'Analytics', {
            organizationUuid,
        });
        can('manage', 'OrganizationMemberProfile', {
            organizationUuid,
        });
        can('manage', 'PinnedItems', {
            organizationUuid,
        });
        can('manage', 'Group', {
            organizationUuid,
        });
        can('view', 'AiAgentThread', {
            organizationUuid,
        });
        can('manage', 'AiAgentThread', {
            organizationUuid,
        });
    },
    [types_1.ServiceAccountScope.SCIM_MANAGE]: ({ organizationUuid, builder: { can }, }) => {
        can('manage', 'OrganizationMemberProfile', {
            organizationUuid,
        });
        can('manage', 'Group', {
            organizationUuid,
        });
    },
};
const applyServiceAccountAbilities = ({ organizationUuid, builder, scopes, }) => {
    scopes.forEach((scope) => {
        applyServiceAccountStaticAbilities[scope]({
            organizationUuid,
            builder,
        });
    });
};
exports.applyServiceAccountAbilities = applyServiceAccountAbilities;
//# sourceMappingURL=serviceAccountAbility.js.map