import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsIn,
  IsOptional,
  IsString,
  IsUUID,
  MaxLength,
  ValidateNested,
} from 'class-validator';

import { CreatePriorityConfigDto } from './create-priority-config.dto';
import { UpdatePriorityConfigDto } from './update-priority-config.dto';

/**
 * File a priority-rule change for approval. CREATE carries a full `create`
 * payload; UPDATE carries the target id + an `update` patch; DELETE carries
 * only the target id.
 */
export class SubmitPriorityRuleChangeDto {
  @ApiProperty({ enum: ['CREATE', 'UPDATE', 'DELETE'] })
  @IsIn(['CREATE', 'UPDATE', 'DELETE'])
  action!: 'CREATE' | 'UPDATE' | 'DELETE';

  @ApiPropertyOptional({ description: 'Target rule id (UPDATE / DELETE)' })
  @IsOptional()
  @IsUUID()
  priorityConfigId?: string;

  @ApiPropertyOptional({ description: 'Proposed new rule (CREATE)' })
  @IsOptional()
  @ValidateNested()
  @Type(() => CreatePriorityConfigDto)
  create?: CreatePriorityConfigDto;

  @ApiPropertyOptional({ description: 'Proposed field changes (UPDATE)' })
  @IsOptional()
  @ValidateNested()
  @Type(() => UpdatePriorityConfigDto)
  update?: UpdatePriorityConfigDto;
}

export class DecidePriorityRuleChangeDto {
  @ApiPropertyOptional({ description: 'Optional note shown to the requester' })
  @IsOptional()
  @IsString()
  @MaxLength(1000)
  decisionNote?: string;
}
