import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';
import { ESTATE_ID_EXAMPLE, GUARD_ID_EXAMPLE, VISIT_SESSION_ID_EXAMPLE } from '../../common/swagger-docs';

export class ScanCheckinDto {
  @ApiProperty({ example: ESTATE_ID_EXAMPLE, description: 'Estate where the gate scan happens.' })
  @IsString()
  estateId!: string;

  @ApiProperty({ example: 'qr-token', description: 'QR token from the visitor pass payload.' })
  @IsString()
  qrToken!: string;

  @ApiProperty({ example: GUARD_ID_EXAMPLE, description: 'Authenticated guard profile ID. Must match the guard user.' })
  @IsString()
  guardId!: string;

  @ApiPropertyOptional({ example: 'Main Gate', description: 'Gate where the visitor entered.' })
  @IsOptional()
  @IsString()
  entryGate?: string;

  @ApiPropertyOptional({ example: 'gate-uuid', description: 'Gate ID where the visitor entered.' })
  @IsOptional()
  @IsString()
  gateId?: string;

  @ApiPropertyOptional({ example: { lat: 6.5244, lng: 3.3792 }, description: 'Optional scanner location metadata.' })
  @IsOptional()
  scanLocation?: Record<string, unknown>;

  @ApiPropertyOptional({
    example: 'gate-tablet-001',
    description: 'Optional scanner device ID. If the guard has no assigned device, first use binds this device to the guard; future mismatches are rejected.'
  })
  @IsOptional()
  @IsString()
  deviceId?: string;

  @ApiPropertyOptional({ example: 'offline-event-001', description: 'Optional client event ID for offline-originated scans.' })
  @IsOptional()
  @IsString()
  offlineEventId?: string;
}

export class ManualCheckinDto {
  @ApiProperty({ example: ESTATE_ID_EXAMPLE, description: 'Estate where the manual check-in happens.' })
  @IsString()
  estateId!: string;

  @ApiProperty({ example: 'ABC12345', description: 'Manual visitor code printed or shared with the visitor.' })
  @IsString()
  visitorCode!: string;

  @ApiProperty({ example: GUARD_ID_EXAMPLE, description: 'Authenticated guard profile ID. Must match the guard user.' })
  @IsString()
  guardId!: string;

  @ApiPropertyOptional({ example: 'Main Gate', description: 'Gate where the visitor entered.' })
  @IsOptional()
  @IsString()
  entryGate?: string;

  @ApiPropertyOptional({ example: 'gate-uuid', description: 'Gate ID where the visitor entered.' })
  @IsOptional()
  @IsString()
  gateId?: string;

  @ApiPropertyOptional({ example: { lat: 6.5244, lng: 3.3792 }, description: 'Optional scanner location metadata.' })
  @IsOptional()
  scanLocation?: Record<string, unknown>;

  @ApiPropertyOptional({
    example: 'gate-tablet-001',
    description: 'Optional scanner device ID. If the guard has no assigned device, first use binds this device to the guard; future mismatches are rejected.'
  })
  @IsOptional()
  @IsString()
  deviceId?: string;

  @ApiPropertyOptional({ example: 'offline-event-001', description: 'Optional client event ID for offline-originated check-ins.' })
  @IsOptional()
  @IsString()
  offlineEventId?: string;
}

export class CheckoutDto {
  @ApiProperty({ example: VISIT_SESSION_ID_EXAMPLE, description: 'Open visit session to check out.' })
  @IsString()
  visitSessionId!: string;

  @ApiProperty({ example: GUARD_ID_EXAMPLE, description: 'Authenticated guard profile ID. Must match the guard user.' })
  @IsString()
  guardId!: string;

  @ApiPropertyOptional({ example: 'Main Gate', description: 'Gate where the visitor exited.' })
  @IsOptional()
  @IsString()
  exitGate?: string;

  @ApiPropertyOptional({ example: 'gate-uuid', description: 'Gate ID where the visitor exited.' })
  @IsOptional()
  @IsString()
  gateId?: string;

  @ApiPropertyOptional({
    example: 'gate-tablet-001',
    description: 'Optional scanner device ID used for checkout. Mismatches are rejected when the guard is already assigned to a device.'
  })
  @IsOptional()
  @IsString()
  deviceId?: string;
}
