import { CapabilityName } from '@humand-packages/common';
import { GrantsDefinitionMap } from '../../../permissions/business/types/grants';
import { SpecificPermissionCode } from '../../../roles/business/models/specificPermission';

/**
 * Grants for the time tracking app control module screen.
 * These determine which actions are visible/available on the control module screen.
 */
export enum TimeTrackingAppGrant {
    VIEW_RECORDS = 'VIEW_RECORDS',
    EDIT_RECORDS = 'EDIT_RECORDS',
    EXPORT_REPORTS = 'EXPORT_REPORTS',
}

export const TIME_TRACKING_APP_GRANTS: TimeTrackingAppGrant[] = Object.values(TimeTrackingAppGrant);

export const TIME_TRACKING_APP_GRANTS_DEFINITION: GrantsDefinitionMap<TimeTrackingAppGrant> = {
    [TimeTrackingAppGrant.VIEW_RECORDS]: {
        generalPermissions: [CapabilityName.MANAGE_TIME_TRACKING],
        specificPermissions: [SpecificPermissionCode.VIEW_TIME_TRACKING_RECORDS],
    },
    [TimeTrackingAppGrant.EDIT_RECORDS]: {
        generalPermissions: [CapabilityName.MANAGE_TIME_TRACKING],
        specificPermissions: [SpecificPermissionCode.EDIT_TIME_TRACKING_RECORDS],
    },
    [TimeTrackingAppGrant.EXPORT_REPORTS]: {
        generalPermissions: [CapabilityName.MANAGE_TIME_TRACKING],
        specificPermissions: [SpecificPermissionCode.EXPORT_TIME_TRACKING_REPORTS],
    },
};

/**
 * All grants for the time tracking module.
 */
export type TimeTrackingGrant = TimeTrackingAppGrant;

export const TIME_TRACKING_GRANTS: TimeTrackingGrant[] = [...TIME_TRACKING_APP_GRANTS];

export const TIME_TRACKING_GRANTS_DEFINITION: GrantsDefinitionMap<TimeTrackingGrant> = {
    ...TIME_TRACKING_APP_GRANTS_DEFINITION,
};
