export enum CategorizedHoursActionType {
    CALCULATE_CATEGORIZED_HOURS = 'CALCULATE_CATEGORIZED_HOURS',
    POLICY_ASSIGNATION_CHANGE = 'POLICY_ASSIGNATION_CHANGE',
    HOUR_CATEGORY_CHANGE = 'HOUR_CATEGORY_CHANGE',
    HOUR_CATEGORY_DELETION = 'HOUR_CATEGORY_DELETION',
    ENTRIES_CHANGE = 'ENTRIES_CHANGE',
    POLICY_HOUR_CATEGORIES_CHANGE = 'POLICY_HOUR_CATEGORIES_CHANGE',
    SCHEDULE_CHANGE = 'SCHEDULE_CHANGE',
}

export type CalculateCategorizedHoursPayload = {
    instanceId: number;
    userIds: number[];
    dateStrings: string[];
};

export type PolicyAssignationChangePayload = {
    instanceId: number;
    policyId: number;
    assignedUserIds: number[];
    unassignedUserIds: number[];
    date: string;
};

export type HourCategoryChangePayload = {
    instanceId: number;
    hourCategoryId: number;
};

export type EntriesChangePayload = {
    instanceId: number;
    userId: number;
    dateString: string;
};

export type PolicyHourCategoriesChangePayload = {
    instanceId: number;
    policyId: number;
    userIds: number[];
    removedHourCategoryIds: number[];
    date: string;
};

export type ScheduleChangePayload = {
    instanceId: number;
    userIds: number[];
    startDate: string;
    endDate: string;
};

export type CategorizedHoursSchedulerMessage =
    | { type: CategorizedHoursActionType.CALCULATE_CATEGORIZED_HOURS; payload: CalculateCategorizedHoursPayload }
    | { type: CategorizedHoursActionType.POLICY_ASSIGNATION_CHANGE; payload: PolicyAssignationChangePayload }
    | { type: CategorizedHoursActionType.HOUR_CATEGORY_CHANGE; payload: HourCategoryChangePayload }
    | { type: CategorizedHoursActionType.HOUR_CATEGORY_DELETION; payload: HourCategoryChangePayload }
    | { type: CategorizedHoursActionType.ENTRIES_CHANGE; payload: EntriesChangePayload }
    | { type: CategorizedHoursActionType.POLICY_HOUR_CATEGORIES_CHANGE; payload: PolicyHourCategoriesChangePayload }
    | { type: CategorizedHoursActionType.SCHEDULE_CHANGE; payload: ScheduleChangePayload };

/**
 * Maximum number of users carried by a single retroactive categorized-hours SQS message.
 * Producer-side chunking is enforced at emission time so each handler invocation does
 * bounded work and respects the SQS visibility timeout. See
 * `humand-packages/monolith/src/api/modules/timeTracking/business/services/policies.ts`
 * for the 3 emission sites that apply this limit.
 *
 * Rationale for 30: the per-message cost is roughly `users × days-of-backfill` categorized-hour
 * rows written in one transaction (worst observed ≈ 90 days of backfill per user). 30 users keeps
 * that worst case (~30 × 90 ≈ 2.7k rows) comfortably within the queue's visibility timeout, while
 * staying large enough to avoid excessive message fan-out for typical policies. It is a deliberately
 * conservative cap, not a measured optimum — revisit it if per-user processing time grows (e.g. more
 * hour categories per policy) or if the visibility timeout changes.
 */
export const CATEGORIZED_HOURS_USER_CHUNK_SIZE = 30;
