import { ApiProperty } from '@nestjs/swagger';
import { IsOptional, IsString, Matches } from 'class-validator';

export class LibraryTrackDto {
  @ApiProperty({ format: 'uuid', required: false })
  id?: string;

  @ApiProperty({ example: 'Placeholder Track', required: false })
  title?: string;

  @ApiProperty({ example: 'Velody', required: false })
  artist?: string;
}

export class SyncEventDto {
  @ApiProperty({ example: 'TRACK' })
  entityType!: string;

  @ApiProperty({ format: 'uuid' })
  entityId!: string;

  @ApiProperty({ example: 'CREATED' })
  action!: string;

  @ApiProperty({ example: '0' })
  eventId!: string;
}

export class SyncBootstrapResponseDto {
  @ApiProperty({ example: '0' })
  nextCursor!: string;

  @ApiProperty({ type: [LibraryTrackDto] })
  tracks!: LibraryTrackDto[];

  @ApiProperty({ type: [SyncEventDto] })
  events!: SyncEventDto[];

  @ApiProperty({ type: [String] })
  deletedTrackIds!: string[];

  @ApiProperty({ example: '2026-05-24T20:00:00.000Z' })
  serverTime!: string;
}

export class SyncChangesQueryDto {
  @ApiProperty({ required: false, example: '0' })
  @IsOptional()
  @IsString()
  @Matches(/^\d+$/)
  after?: string;
}

export class SyncChangesResponseDto extends SyncBootstrapResponseDto {}
