import { z } from 'zod';

// ── Export Types ─────────────────────────────────────────────

export type ExportFormat = 'csv' | 'json';
export type ExportType = 'users' | 'audit' | 'telemetry' | 'usage' | 'subscriptions' | 'licenses';
export type ExportStatus = 'pending' | 'processing' | 'ready' | 'failed' | 'expired';

export interface ExportJobDoc {
  id: string;
  productId: string;
  type: ExportType;
  format: ExportFormat;
  filters: Record<string, unknown>;
  status: ExportStatus;
  requestedBy: string;
  blobUrl?: string;
  data?: string;
  fileName?: string;
  rowCount?: number;
  fileSizeBytes?: number;
  error?: string;
  startedAt?: string;
  completedAt?: string;
  expiresAt?: string;
  createdAt: string;
  _ts?: number;
}

// ── Schemas ──────────────────────────────────────────────────

export const CreateExportSchema = z.object({
  type: z.enum(['users', 'audit', 'telemetry', 'usage', 'subscriptions', 'licenses']),
  format: z.enum(['csv', 'json']).default('csv'),
  filters: z.record(z.unknown()).default({}),
});

export type CreateExportInput = z.infer<typeof CreateExportSchema>;
