export type OTAStatus =
  | "INSTALLED" // Green Check
  | "INVALID"
  | "MISSING"
  | "STAGED"; // Green Half Check

export interface OTAArtifactInfo {
  hash: string;
  identifier: string;
  miniHash: string;
  name?: string;
  size: number;
  version?: string;
}

export interface OTARequest {
  currentSize: number;
  downloaderActive: boolean;
  downloaderName: string;
  errorCount: number;
  fileNotFoundCount: number;
  kabId: string;
  lastErrorReason?: string;
  lastUpdateTime: number;
}

export interface OTAArtifactResponse {
  artifactInfo?: OTAArtifactInfo;
  done: boolean;
  error?: string;
  requests: Record<string, OTARequest>;
  status: OTAStatus;
}

export type UpdaterStatus =
  | "downloading"
  | "error"
  | "idle"
  | "pending"
  | "ready";

export interface UpdaterItem {
  manifest?: boolean;
  error?: string;
  errorCount?: number;
  id: string;
  label?: string;
  name?: string;
  progress?: number;
  size?: number;
  status: UpdaterStatus;
}

/**
 * Configuration options for OTA model instances.
 *
 * This interface defines the initial configuration for the OTA model, including
 * any pre-existing artifact data that should be loaded during model initialization.
 * In most cases, the OTA model will automatically load artifacts from the OTA service,
 * but this option allows for pre-loading or testing scenarios.
 *
 * @example Basic OTA Model Creation
 * ```typescript
 * // Most common usage - let model load artifacts automatically
 * const otaModel = Ota.instance('system-updates').build();
 *
 * // The model will automatically:
 * // - Connect to OTA service
 * // - Load current artifacts
 * // - Subscribe to real-time updates
 * ```
 *
 * @example Pre-loaded Artifacts (Advanced)
 * ```typescript
 * // Advanced usage with pre-loaded artifact data
 * const mockArtifacts: OTAArtifactResponse[] = [
 *   {
 *     artifactInfo: {
 *       identifier: 'system-update-v1.2.0',
 *       name: 'System Update',
 *       version: '1.2.0',
 *       size: 52428800, // 50MB
 *       hash: 'sha256:abc123...',
 *       miniHash: 'abc123'
 *     },
 *     status: 'STAGED',
 *     done: true,
 *     requests: {
 *       'primary': {
 *         currentSize: 52428800,
 *         downloaderActive: false,
 *         downloaderName: 'system-updater',
 *         errorCount: 0,
 *         fileNotFoundCount: 0,
 *         kabId: 'system-update-v1.2.0',
 *         lastUpdateTime: Date.now()
 *       }
 *     }
 *   }
 * ];
 *
 * const options: UpdaterOptions = {
 *   otaArtifactResponse: mockArtifacts
 * };
 *
 * const otaModel = Ota.instance('preloaded-updater')
 *   .options(options)
 *   .build();
 * ```
 *
 * @example Testing Scenarios
 * ```typescript
 * // Create OTA model with test data for different scenarios
 * const createTestOtaModel = (scenario: 'downloading' | 'pending' | 'error') => {
 *   const testArtifacts: OTAArtifactResponse[] = [];
 *
 *   switch (scenario) {
 *     case 'downloading':
 *       testArtifacts.push({
 *         artifactInfo: {
 *           identifier: 'app-update-v2.1.0',
 *           name: 'Application Update',
 *           version: '2.1.0',
 *           size: 104857600, // 100MB
 *           hash: 'sha256:def456...',
 *           miniHash: 'def456'
 *         },
 *         status: 'MISSING',
 *         done: false,
 *         requests: {
 *           'primary': {
 *             currentSize: 31457280, // 30MB downloaded
 *             downloaderActive: true,
 *             downloaderName: 'app-updater',
 *             errorCount: 0,
 *             fileNotFoundCount: 0,
 *             kabId: 'app-update-v2.1.0',
 *             lastUpdateTime: Date.now()
 *           }
 *         }
 *       });
 *       break;
 *
 *     case 'pending':
 *       testArtifacts.push({
 *         artifactInfo: {
 *           identifier: 'security-patch-v1.0.1',
 *           name: 'Security Patch',
 *           version: '1.0.1',
 *           size: 10485760, // 10MB
 *           hash: 'sha256:ghi789...',
 *           miniHash: 'ghi789'
 *         },
 *         status: 'STAGED',
 *         done: true,
 *         requests: {
 *           'primary': {
 *             currentSize: 10485760,
 *             downloaderActive: false,
 *             downloaderName: 'security-updater',
 *             errorCount: 0,
 *             fileNotFoundCount: 0,
 *             kabId: 'security-patch-v1.0.1',
 *             lastUpdateTime: Date.now()
 *           }
 *         }
 *       });
 *       break;
 *
 *     case 'error':
 *       testArtifacts.push({
 *         status: 'INVALID',
 *         done: false,
 *         error: 'Checksum verification failed',
 *         requests: {
 *           'primary': {
 *             currentSize: 0,
 *             downloaderActive: false,
 *             downloaderName: 'failed-updater',
 *             errorCount: 3,
 *             fileNotFoundCount: 0,
 *             kabId: 'failed-update-v1.0.0',
 *             lastUpdateTime: Date.now(),
 *             lastErrorReason: 'Checksum verification failed'
 *           }
 *         }
 *       });
 *       break;
 *   }
 *
 *   return Ota.instance(`test-${scenario}`)
 *     .options({ otaArtifactResponse: testArtifacts })
 *     .build();
 * };
 * ```
 *
 * @category Model Configuration
 * @category System Integration
 */
export interface UpdaterOptions {
  otaArtifactResponse: OTAArtifactResponse[];
}
