// System account types based on backend SystemAccountsService

export type SystemAccountType =
  | 'DISTRIBUTION_POOL'
  | 'BLACK_HOLE'
  | 'CIRCULATION_POOL'
  | 'SYSTEM_OPERATION'
  | 'SYSTEM_PROVINCE'
  | 'SYSTEM_CITY'
  | 'COST_ACCOUNT'
  | 'OPERATION_ACCOUNT'
  | 'HQ_COMMUNITY'
  | 'RWAD_POOL_PENDING';

export type AccountSource = 'local' | 'synced';

export interface SystemAccount {
  accountType: SystemAccountType;
  regionCode?: string | null;  // 区域代码（省/市代码，如 440000, 440100）
  name?: string;
  description?: string;
  totalContribution?: string;
  contributionBalance?: string;
  contributionNeverExpires?: boolean;
  // 挖矿数据
  totalMined?: string;
  availableBalance?: string;
  miningContribution?: string;
  miningLastSyncedAt?: string;
  syncedAt?: string;
  createdAt?: string;
  source: AccountSource;
}

export interface SystemAccountsResponse {
  accounts: SystemAccount[];
  total: number;
}

export interface MiningConfig {
  totalShares: string;
  distributionPool: string;
  remainingDistribution: string;
  currentEra: number;
  isActive: boolean;
  activatedAt: string | null;
}

export interface CirculationPool {
  totalShares: string;
  totalCash: string;
}

export interface SystemAccountsSummary {
  systemAccounts: {
    count: number;
    totalContribution: string;
  };
  syncedContributions: {
    count: number;
    totalBalance: string;
  };
  miningConfig: MiningConfig | null;
  circulationPool: CirculationPool | null;
}

// Account display metadata
export interface AccountDisplayInfo {
  label: string;
  description: string;
  color: string;
  bgColor: string;
  icon: 'coins' | 'flame' | 'shopping-cart' | 'building' | 'wallet' | 'landmark' | 'box';
}

export const ACCOUNT_DISPLAY_INFO: Record<string, AccountDisplayInfo> = {
  DISTRIBUTION_POOL: {
    label: '分发池',
    description: '用于挖矿分发的代币池',
    color: 'text-green-600',
    bgColor: 'bg-green-50',
    icon: 'coins',
  },
  BLACK_HOLE: {
    label: '黑洞账户',
    description: '永久销毁的代币',
    color: 'text-orange-600',
    bgColor: 'bg-orange-50',
    icon: 'flame',
  },
  CIRCULATION_POOL: {
    label: '流通池',
    description: '市场流通中的代币',
    color: 'text-blue-600',
    bgColor: 'bg-blue-50',
    icon: 'shopping-cart',
  },
  SYSTEM_OPERATION: {
    label: '系统运营账户',
    description: '系统运营分配账户',
    color: 'text-purple-600',
    bgColor: 'bg-purple-50',
    icon: 'building',
  },
  SYSTEM_PROVINCE: {
    label: '省级系统账户',
    description: '无授权商省级账户',
    color: 'text-indigo-600',
    bgColor: 'bg-indigo-50',
    icon: 'landmark',
  },
  SYSTEM_CITY: {
    label: '市级系统账户',
    description: '无授权商市级账户',
    color: 'text-pink-600',
    bgColor: 'bg-pink-50',
    icon: 'landmark',
  },
  COST_ACCOUNT: {
    label: '成本账户',
    description: '成本分配账户',
    color: 'text-slate-600',
    bgColor: 'bg-slate-50',
    icon: 'wallet',
  },
  OPERATION_ACCOUNT: {
    label: '运营账户',
    description: '12% 运营收入账户',
    color: 'text-teal-600',
    bgColor: 'bg-teal-50',
    icon: 'building',
  },
  HQ_COMMUNITY: {
    label: '总部社区账户',
    description: '总部社区分配账户',
    color: 'text-cyan-600',
    bgColor: 'bg-cyan-50',
    icon: 'building',
  },
  RWAD_POOL_PENDING: {
    label: 'RWAD 待注入池',
    description: 'RWAD 代币待注入池',
    color: 'text-amber-600',
    bgColor: 'bg-amber-50',
    icon: 'box',
  },
};

// Helper function to get display info
export function getAccountDisplayInfo(accountType: string): AccountDisplayInfo {
  return ACCOUNT_DISPLAY_INFO[accountType] || {
    label: accountType,
    description: '',
    color: 'text-gray-600',
    bgColor: 'bg-gray-50',
    icon: 'building',
  };
}