/**
 * Synor Mining SDK Types
 * Pool connections, block templates, hashrate stats, and GPU management.
 */

// Device type
export type DeviceType = 'cpu' | 'gpu_nvidia' | 'gpu_amd' | 'asic';

// Device status
export type DeviceStatus = 'idle' | 'mining' | 'error' | 'offline';

// Connection status
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';

// Time period for stats
export type TimePeriod = 'hour' | 'day' | 'week' | 'month' | 'all';

// Submit result status
export type SubmitResultStatus = 'accepted' | 'rejected' | 'stale';

// Pool configuration
export interface PoolConfig {
  url: string;
  user: string;
  password?: string;
  algorithm?: string;
  difficulty?: number;
}

// Stratum connection
export interface StratumConnection {
  id: string;
  pool: string;
  status: ConnectionStatus;
  algorithm: string;
  difficulty: number;
  connectedAt: number;
  lastShareAt?: number;
  acceptedShares: number;
  rejectedShares: number;
  staleShares: number;
}

// Block template
export interface BlockTemplate {
  id: string;
  previousBlockHash: string;
  merkleRoot: string;
  timestamp: number;
  bits: string;
  height: number;
  coinbaseValue: string;
  transactions: TemplateTransaction[];
  target: string;
  algorithm: string;
  extraNonce: string;
}

// Template transaction
export interface TemplateTransaction {
  txid: string;
  data: string;
  fee: string;
  weight: number;
}

// Mined work
export interface MinedWork {
  templateId: string;
  nonce: string;
  extraNonce: string;
  timestamp: number;
  hash: string;
}

// Submit result
export interface SubmitResult {
  status: SubmitResultStatus;
  reason?: string;
  share: ShareInfo;
  blockFound: boolean;
  blockHash?: string;
  reward?: string;
}

// Share info
export interface ShareInfo {
  hash: string;
  difficulty: number;
  timestamp: number;
  accepted: boolean;
}

// Hashrate
export interface Hashrate {
  current: number;
  average1h: number;
  average24h: number;
  peak: number;
  unit: string;
}

// Mining stats
export interface MiningStats {
  hashrate: Hashrate;
  shares: ShareStats;
  uptime: number;
  efficiency: number;
  powerConsumption?: number;
  temperature?: DeviceTemperature;
  earnings: EarningsSnapshot;
}

// Share stats
export interface ShareStats {
  accepted: number;
  rejected: number;
  stale: number;
  total: number;
  acceptRate: number;
}

// Device temperature
export interface DeviceTemperature {
  current: number;
  max: number;
  throttling: boolean;
}

// Earnings snapshot
export interface EarningsSnapshot {
  today: string;
  yesterday: string;
  thisWeek: string;
  thisMonth: string;
  total: string;
  currency: string;
}

// Detailed earnings
export interface Earnings {
  period: TimePeriod;
  startDate: number;
  endDate: number;
  amount: string;
  blocks: number;
  shares: number;
  averageHashrate: number;
  currency: string;
  breakdown: EarningsBreakdown[];
}

// Earnings breakdown
export interface EarningsBreakdown {
  date: number;
  amount: string;
  blocks: number;
  shares: number;
  hashrate: number;
}

// Mining device
export interface MiningDevice {
  id: string;
  name: string;
  type: DeviceType;
  status: DeviceStatus;
  hashrate: number;
  temperature: number;
  fanSpeed: number;
  powerDraw: number;
  memoryUsed: number;
  memoryTotal: number;
  driver?: string;
  firmware?: string;
}

// Device config
export interface DeviceConfig {
  enabled: boolean;
  intensity?: number;
  powerLimit?: number;
  coreClockOffset?: number;
  memoryClockOffset?: number;
  fanSpeed?: number;
}

// Worker info
export interface WorkerInfo {
  id: string;
  name: string;
  status: ConnectionStatus;
  hashrate: Hashrate;
  shares: ShareStats;
  devices: MiningDevice[];
  lastSeen: number;
  uptime: number;
}

// Pool stats
export interface PoolStats {
  url: string;
  workers: number;
  hashrate: number;
  difficulty: number;
  lastBlock: number;
  blocksFound24h: number;
  luck: number;
}

// Mining algorithm
export interface MiningAlgorithm {
  name: string;
  displayName: string;
  hashUnit: string;
  profitability: string;
  difficulty: number;
  blockReward: string;
  blockTime: number;
}

// Mining config
export interface MiningConfig {
  apiKey: string;
  endpoint?: string;
  timeout?: number;
  retries?: number;
  debug?: boolean;
}

// Internal response types
export interface DevicesResponse {
  devices: MiningDevice[];
}

export interface WorkersResponse {
  workers: WorkerInfo[];
}

export interface AlgorithmsResponse {
  algorithms: MiningAlgorithm[];
}
