import 'package:flutter/material.dart';

enum ClientStatus {
  offline,         // 离线（心跳异常，红色）
  online,          // 在线（心跳正常，绿色）
  mining,          // 挖矿中（租约挖矿，黄色）
  sustainingMining, // 持续挖矿中（持续挖矿，蓝色）
}

extension ClientStatusExtension on ClientStatus {
  String get displayName {
    switch (this) {
      case ClientStatus.offline:
        return '离线';
      case ClientStatus.online:
        return '在线';
      case ClientStatus.mining:
        return '挖矿中';
      case ClientStatus.sustainingMining:
        return '持续挖矿中';
    }
  }
  
  Color get color {
    switch (this) {
      case ClientStatus.offline:
        return Colors.red;
      case ClientStatus.online:
        return Colors.green;
      case ClientStatus.mining:
        return Colors.orange;
      case ClientStatus.sustainingMining:
        return Colors.blue;
    }
  }
}

class ClientInfo {
  final String version;
  final String auth;
  final List<GPUInfo> gpus;
  final String machineCode;
  final ClientStatus status;
  final MiningInfo? miningInfo;

  ClientInfo({
    required this.version,
    required this.auth,
    required this.gpus,
    required this.machineCode,
    required this.status,
    this.miningInfo,
  });
}

class GPUInfo {
  final int index;
  final String brand;
  final String model;
  final double? memory; // MB

  GPUInfo({
    required this.index,
    required this.brand,
    required this.model,
    this.memory,
  });

  String get displayName => '$brand $model${memory != null ? ' (${(memory! / 1024).toStringAsFixed(1)} GB)' : ''}';

  Map<String, dynamic> toJson() => {
        'index': index,
        'brand': brand,
        'model': model,
        'mem': memory,
      };
}

class MiningInfo {
  final String coin;
  final String algo;
  final String pool;
  final String poolUrl;
  final String walletAddress;
  final String workerId;
  final int? pid;
  final String? miner;
  final int endTimestamp;

  MiningInfo({
    required this.coin,
    required this.algo,
    required this.pool,
    required this.poolUrl,
    required this.walletAddress,
    required this.workerId,
    this.pid,
    this.miner,
    required this.endTimestamp,
  });
}
