import { ApiProperty } from '@nestjs/swagger';
import type { SyncLog } from '@prisma/client';

export class SyncLogDto {
  @ApiProperty()
  id!: string;

  @ApiProperty()
  type!: 'CATEGORIES' | 'PRODUCTS';

  @ApiProperty()
  status!: 'RUNNING' | 'SUCCESS' | 'FAILED';

  @ApiProperty({ nullable: true })
  message!: string | null;

  @ApiProperty()
  startedAt!: string;

  @ApiProperty({ nullable: true })
  finishedAt!: string | null;

  static from(log: SyncLog): SyncLogDto {
    return {
      id: log.id.toString(),
      type: log.type,
      status: log.status,
      message: log.message,
      startedAt: log.startedAt.toISOString(),
      finishedAt: log.finishedAt ? log.finishedAt.toISOString() : null,
    };
  }
}
