import { Expose, Type } from 'class-transformer';
import { ArrayMinSize, IsArray, IsDefined, IsIn, ValidateNested } from 'class-validator';
import { HourCategorizationFields } from '../../../business/types/hourCategorization/hourCategorizationFields';
import { HourCategorizationLogicOperators } from '../../../business/types/hourCategorization/hourCategorizationLogicOperators';
import { HourCategorizationOperators } from '../../../business/types/hourCategorization/hourCategorizationOperators';
import { HourCategorizationValidValues } from '../../../business/types/hourCategorization/hourCategorizationValidValues';
import { HourCategorizationValueTypes } from '../../../business/types/hourCategorization/hourCategorizationValueTypes';
import { IsValidHourCategorizationRule } from '../../validators/isValidHourCategorizationRule/isValidHourCategorizationRule';

export class RuleConditionVC {
    @IsDefined()
    @Expose()
    @IsIn(Object.values(HourCategorizationFields))
    field!: HourCategorizationFields;

    @IsDefined()
    @Expose()
    @IsIn(Object.values(HourCategorizationOperators))
    operator!: HourCategorizationOperators;

    @IsDefined()
    @Expose()
    @IsIn(Object.values(HourCategorizationValueTypes))
    valueType!: HourCategorizationValueTypes;

    @IsDefined()
    @Expose()
    @IsValidHourCategorizationRule()
    value!: HourCategorizationValidValues;
}

export class RuleLogicVC {
    @IsDefined()
    @Expose()
    @IsArray()
    @ArrayMinSize(1)
    @ValidateNested({ each: true })
    @Type(() => RuleConditionVC)
    conditions!: RuleConditionVC[];

    @IsDefined()
    @Expose()
    @IsIn(Object.values(HourCategorizationLogicOperators))
    operator!: HourCategorizationLogicOperators;
}
