import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { EstateGateType } from '@prisma/client';
import { IsBoolean, IsEnum, IsObject, IsOptional, IsString, MaxLength } from 'class-validator';
import { ESTATE_ID_EXAMPLE } from '../../common/swagger-docs';

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

  @ApiProperty({ example: 'Main Gate', description: 'Gate display name.' })
  @IsString()
  @MaxLength(80)
  name!: string;

  @ApiPropertyOptional({ enum: EstateGateType, example: EstateGateType.MAIN, description: 'Gate type.' })
  @IsOptional()
  @IsEnum(EstateGateType)
  type?: EstateGateType;

  @ApiPropertyOptional({ example: 'Primary visitor entry gate.', description: 'Optional gate description.' })
  @IsOptional()
  @IsString()
  @MaxLength(240)
  description?: string;

  @ApiPropertyOptional({ example: { cameraId: 'cam-main-001' }, description: 'Optional gate metadata.' })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;
}

export class UpdateGateDto {
  @ApiPropertyOptional({ example: 'Service Gate', description: 'Gate display name.' })
  @IsOptional()
  @IsString()
  @MaxLength(80)
  name?: string;

  @ApiPropertyOptional({ enum: EstateGateType, example: EstateGateType.SERVICE, description: 'Gate type.' })
  @IsOptional()
  @IsEnum(EstateGateType)
  type?: EstateGateType;

  @ApiPropertyOptional({ example: 'Delivery and service personnel gate.', description: 'Gate description.' })
  @IsOptional()
  @IsString()
  @MaxLength(240)
  description?: string;

  @ApiPropertyOptional({ example: true, description: 'Whether the gate is active.' })
  @IsOptional()
  @IsBoolean()
  isActive?: boolean;

  @ApiPropertyOptional({ example: { cameraId: 'cam-service-001' }, description: 'Replace gate metadata.' })
  @IsOptional()
  @IsObject()
  metadata?: Record<string, unknown>;
}
