import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsObject, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { ESTATE_ID_EXAMPLE } from '../../common/swagger-docs';

export class OfflineSyncItemDto {
  @ApiProperty({ example: 'offline-event-001', description: 'Client-generated event ID for idempotency.' })
  @IsString()
  clientEventId!: string;

  @ApiProperty({ example: 'VISITOR_CHECKED_IN', description: 'Offline event type recorded by the client.' })
  @IsString()
  eventType!: string;

  @ApiProperty({ example: { visitorCode: 'ABC12345' }, description: 'Event payload captured offline.' })
  @IsObject()
  payload!: Record<string, unknown>;
}

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

  @ApiProperty({ example: 'guard-device-001', description: 'Client device submitting the offline event batch.' })
  @IsString()
  deviceId!: string;

  @ApiProperty({ type: [OfflineSyncItemDto], description: 'Batch of offline events to store.' })
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => OfflineSyncItemDto)
  items!: OfflineSyncItemDto[];
}
