import { VisitorPassType } from '@prisma/client';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsDate, IsEnum, IsInt, IsOptional, IsString, Min } from 'class-validator';
import { ESTATE_ID_EXAMPLE, RESIDENT_ID_EXAMPLE, VISITOR_ID_EXAMPLE } from '../../common/swagger-docs';

export class CreateVisitorPassDto {
  @ApiProperty({ example: ESTATE_ID_EXAMPLE, description: 'Estate that owns this visitor pass.' })
  @IsString()
  estateId!: string;

  @ApiProperty({ example: RESIDENT_ID_EXAMPLE, description: 'Resident hosting the visitor. Must belong to the estate.' })
  @IsString()
  hostResidentId!: string;

  @ApiProperty({ example: VISITOR_ID_EXAMPLE, description: 'Visitor receiving the pass. Must belong to the estate.' })
  @IsString()
  visitorId!: string;

  @ApiProperty({ example: '2026-05-16T08:00:00.000Z', description: 'Start of pass validity window.' })
  @Type(() => Date)
  @IsDate()
  validFrom!: Date;

  @ApiProperty({ example: '2026-05-16T18:00:00.000Z', description: 'End of pass validity window. Must be after validFrom.' })
  @Type(() => Date)
  @IsDate()
  validUntil!: Date;

  @ApiProperty({ enum: VisitorPassType, example: VisitorPassType.SINGLE_USE, description: 'Pass policy type.' })
  @IsEnum(VisitorPassType)
  passType!: VisitorPassType;

  @ApiPropertyOptional({ example: 1, description: 'Maximum allowed entries. Defaults to 1 for SINGLE_USE, 999 otherwise.' })
  @IsOptional()
  @IsInt()
  @Min(1)
  maxEntries?: number;
}
