import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ResidentRequestCategory, ResidentRequestPriority, ResidentRequestStatus } from '@prisma/client';
import { IsEnum, IsObject, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
import { ESTATE_ID_EXAMPLE, RESIDENT_ID_EXAMPLE, USER_ID_EXAMPLE } from '../../common/swagger-docs';

export class CreateResidentRequestDto {
  @ApiProperty({ example: ESTATE_ID_EXAMPLE, description: 'Estate that owns the request.' })
  @IsString()
  estateId!: string;

  @ApiPropertyOptional({ example: RESIDENT_ID_EXAMPLE, description: 'Resident profile creating the request. Defaults to signed-in resident.' })
  @IsOptional()
  @IsString()
  residentId?: string;

  @ApiProperty({ enum: ResidentRequestCategory, example: ResidentRequestCategory.SECURITY })
  @IsEnum(ResidentRequestCategory)
  category!: ResidentRequestCategory;

  @ApiPropertyOptional({ enum: ResidentRequestPriority, example: ResidentRequestPriority.NORMAL })
  @IsOptional()
  @IsEnum(ResidentRequestPriority)
  priority?: ResidentRequestPriority;

  @ApiProperty({ example: 'Suspicious movement near Block B', description: 'Request title.' })
  @IsString()
  @MinLength(3)
  @MaxLength(120)
  title!: string;

  @ApiProperty({ example: 'I noticed unknown persons around the street light area.', description: 'Request details.' })
  @IsString()
  @MinLength(5)
  @MaxLength(1200)
  description!: string;

  @ApiPropertyOptional({ example: { location: 'Block B' }, description: 'Optional request metadata.' })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;
}

export class RespondResidentRequestDto {
  @ApiProperty({ example: 'A patrol has been assigned to check the area.', description: 'Response message.' })
  @IsString()
  @MinLength(2)
  @MaxLength(1200)
  message!: string;

  @ApiPropertyOptional({ enum: ResidentRequestStatus, example: ResidentRequestStatus.IN_PROGRESS })
  @IsOptional()
  @IsEnum(ResidentRequestStatus)
  status?: ResidentRequestStatus;

  @ApiPropertyOptional({ example: USER_ID_EXAMPLE, description: 'Optional user assigned to the request.' })
  @IsOptional()
  @IsString()
  assignedToId?: string;

  @ApiPropertyOptional({ example: { patrol: 'night-shift' }, description: 'Optional response metadata.' })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;
}
