import { IsNotEmpty, IsString, IsNumber, IsBoolean, IsOptional, IsArray, IsEnum, ValidateNested, IsObject } from 'class-validator'; import { Type } from 'class-transformer'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ClaimWorkflowStep } from 'src/Types&Enums/claim-request-management/claim-workflow-steps.enum'; import { WorkflowStep } from 'src/Types&Enums/blame-request-management/blameWorkflow-steps.enum'; import { Types } from 'mongoose'; // Combined enum for validation const AllWorkflowSteps = { ...WorkflowStep, ...ClaimWorkflowStep }; export class ClaimStepFieldDto { @ApiProperty({ description: 'Unique identifier for the field', example: '67fa10c259e15f231a2d1001' }) @IsNotEmpty() id: Types.ObjectId; @ApiProperty({ description: 'Field name in Farsi', example: 'قطعات خارجی' }) @IsNotEmpty() @IsString() name_fa: string; @ApiProperty({ description: 'Field name in English', example: 'outerParts' }) @IsNotEmpty() @IsString() name_en: string; @ApiPropertyOptional({ description: 'Field label in Farsi', example: 'قطعات خارجی آسیب‌دیده' }) @IsOptional() @IsString() label_fa?: string; @ApiPropertyOptional({ description: 'Field label in English', example: 'Damaged Outer Parts' }) @IsOptional() @IsString() label_en?: string; @ApiPropertyOptional({ description: 'Placeholder text in Farsi', example: 'قطعات خارجی آسیب‌دیده را انتخاب کنید' }) @IsOptional() @IsString() placeholder_fa?: string; @ApiPropertyOptional({ description: 'Placeholder text in English', example: 'Select damaged outer parts' }) @IsOptional() @IsString() placeholder_en?: string; @ApiPropertyOptional({ description: 'Possible values for select/multiselect fields (null for non-select fields)', example: null, nullable: true, default: null }) @IsOptional() value?: Object[] | null; @ApiProperty({ description: 'Data type of the field', example: 'multiselect', enum: ['string', 'number', 'boolean', 'date', 'select', 'multiselect', 'file', 'textarea', 'email', 'phone', 'object'] }) @IsNotEmpty() @IsString() dataType: string; @ApiPropertyOptional({ description: 'Whether the field is required', example: true, default: false }) @IsOptional() @IsBoolean() required?: boolean; @ApiPropertyOptional({ description: 'Validation rules for the field', example: { minItems: 1, maxItems: 13 } }) @IsOptional() @IsObject() validation?: Object; @ApiPropertyOptional({ description: 'Display order of the field in the form', example: 1 }) @IsOptional() @IsNumber() order?: number; @ApiPropertyOptional({ description: 'Whether the field is active', example: true, default: true }) @IsOptional() @IsBoolean() isActive?: boolean; } export class CreateClaimWorkflowStepDto { @ApiProperty({ description: 'Unique key identifying the claim workflow step', example: 'CLAIM_CREATED', enum: AllWorkflowSteps }) @IsNotEmpty() @IsEnum(AllWorkflowSteps) stepKey: ClaimWorkflowStep | WorkflowStep; @ApiProperty({ description: 'Workflow type: CLAIM for claim workflow', example: 'CLAIM', default: 'CLAIM' }) @IsNotEmpty() @IsString() type: string; @ApiProperty({ description: 'Order number of the step in the claim workflow', example: 1 }) @IsNotEmpty() @IsNumber() stepNumber: number; @ApiPropertyOptional({ description: 'Whether the step is active', example: true, default: true }) @IsOptional() @IsBoolean() isActive?: boolean; @ApiProperty({ description: 'Step name in Farsi', example: 'ایجاد درخواست خسارت' }) @IsNotEmpty() @IsString() stepName_fa: string; @ApiProperty({ description: 'Step name in English', example: 'Create Claim Request' }) @IsNotEmpty() @IsString() stepName_en: string; @ApiPropertyOptional({ description: 'Step description in Farsi', example: 'ایجاد درخواست خسارت از پرونده تعیین تقصیر تکمیل شده' }) @IsOptional() @IsString() description_fa?: string; @ApiPropertyOptional({ description: 'Step description in English', example: 'Create claim request from completed blame case' }) @IsOptional() @IsString() description_en?: string; @ApiPropertyOptional({ description: 'Category of the step', example: 'CLAIM', enum: ['CLAIM', 'EXPERT', 'INSURER', 'FINAL'] }) @IsOptional() @IsString() category?: string; @ApiPropertyOptional({ description: 'Dynamic fields for this step', type: [ClaimStepFieldDto], example: [] }) @IsOptional() @IsArray() @ValidateNested({ each: true }) @Type(() => ClaimStepFieldDto) fields?: ClaimStepFieldDto[]; @ApiPropertyOptional({ description: 'Steps that must be completed before this step', example: [], enum: AllWorkflowSteps, isArray: true }) @IsOptional() @IsArray() @IsEnum(AllWorkflowSteps, { each: true }) requiredPreviousSteps?: (ClaimWorkflowStep | WorkflowStep)[]; @ApiPropertyOptional({ description: 'Possible next steps after completing this step', example: ['SELECT_OUTER_PARTS'], enum: AllWorkflowSteps, isArray: true }) @IsOptional() @IsArray() @IsEnum(AllWorkflowSteps, { each: true }) nextPossibleSteps?: (ClaimWorkflowStep | WorkflowStep)[]; @ApiPropertyOptional({ description: 'Additional metadata for the step', example: { icon: 'file-plus', color: '#8B5CF6' } }) @IsOptional() @IsObject() metadata?: Record; @ApiPropertyOptional({ description: 'Estimated duration in minutes', example: 1 }) @IsOptional() @IsNumber() estimatedDuration?: number; @ApiPropertyOptional({ description: 'Roles allowed to access this step', example: ['user', 'damage_expert', 'admin'] }) @IsOptional() @IsArray() @IsString({ each: true }) allowedRoles?: string[]; }