/**
 * Offline Sync DTOs
 *
 * @module Mobile
 */

import { SyncOperation, SyncStatus, ConflictResolution } from '../entities/offline-sync-queue.entity';
import { ConflictType, ConflictResolutionType } from '../entities/sync-conflict.entity';

export class CreateSyncQueueItemDto {
  userId: string;
  deviceId: string;
  tenantId: string;
  sessionId?: string;
  entityType: string;
  entityId?: string;
  operation: SyncOperation;
  payload: Record<string, any>;
  metadata?: Record<string, any>;
  sequenceNumber: number;
  dependsOn?: string;
}

export class ProcessSyncBatchDto {
  items: CreateSyncQueueItemDto[];
}

export class ResolveSyncConflictDto {
  resolution: ConflictResolutionType;
  mergedData?: Record<string, any>;
}

export class SyncQueueResponseDto {
  id: string;
  userId: string;
  deviceId: string;
  sessionId?: string;
  entityType: string;
  entityId?: string;
  operation: SyncOperation;
  payload: Record<string, any>;
  sequenceNumber: number;
  status: SyncStatus;
  retryCount: number;
  lastError?: string;
  processedAt?: Date;
  conflictData?: Record<string, any>;
  conflictResolution?: ConflictResolution;
  createdAt: Date;
}

export class SyncConflictResponseDto {
  id: string;
  syncQueueId: string;
  userId: string;
  conflictType: ConflictType;
  localData: Record<string, any>;
  serverData: Record<string, any>;
  resolution?: ConflictResolutionType;
  mergedData?: Record<string, any>;
  resolvedBy?: string;
  resolvedAt?: Date;
  createdAt: Date;
}

export class SyncFilterDto {
  userId?: string;
  deviceId?: string;
  sessionId?: string;
  entityType?: string;
  status?: SyncStatus;
  limit?: number;
  offset?: number;
}

export class SyncResultDto {
  success: boolean;
  processed: number;
  failed: number;
  conflicts: number;
  errors?: { id: string; error: string }[];
}

export class SyncStatusDto {
  pendingCount: number;
  processingCount: number;
  failedCount: number;
  conflictCount: number;
  lastSyncAt?: Date;
}
