import { ValidationClass, HierarchicalRelations } from '@humand-packages/common';
import { Expose, Type } from 'class-transformer';
import { ArrayMinSize, ArrayUnique, IsArray, IsBoolean, IsDefined, IsIn, IsNumber, IsOptional, ValidateNested } from 'class-validator';

export class TimeTrackingApprovalUsersGatheringVC extends ValidationClass {
    @IsOptional()
    @Expose()
    @IsArray()
    @IsNumber({}, { each: true })
    @ArrayUnique()
    userIds?: number[];

    @IsOptional()
    @Expose()
    @IsArray()
    @IsNumber({}, { each: true })
    @ArrayUnique()
    itemIds?: number[];

    @IsOptional()
    @Expose()
    @IsArray()
    @IsIn(Object.values(HierarchicalRelations), { each: true, message: 'Bad relations sent' })
    relations?: string[];

    @IsOptional()
    @Expose()
    @IsBoolean()
    designatedReviewer?: boolean;
}

export class UpdateTimeTrackingApprovalUsersVC extends ValidationClass {
    @ValidateNested({ each: true })
    @Type(() => TimeTrackingApprovalUsersGatheringVC)
    @Expose()
    @IsDefined()
    @IsArray()
    @ArrayMinSize(1)
    approvalUsers!: TimeTrackingApprovalUsersGatheringVC[];
}

/** PUT `/policies/:id/approval-users` — allows `approvalUsers: []` to clear policy override (fallback to global). */
export class UpdateTimeTrackingPolicyApprovalUsersVC extends ValidationClass {
    @ValidateNested({ each: true })
    @Type(() => TimeTrackingApprovalUsersGatheringVC)
    @Expose()
    @IsDefined()
    @IsArray()
    approvalUsers!: TimeTrackingApprovalUsersGatheringVC[];
}
