import type { Agent, Share, ServerConfig, ServerInfo } from '../types';

const VALID_XMR_WALLET = '4' + 'A'.repeat(94);

export function mockServerConfig(overrides: Partial<ServerConfig> = {}): ServerConfig {
  return {
    port: 8080,
    data_dir: './data',
    pool: {
      host: 'pool.supportxmr.com',
      port: 3333,
      use_tls: false,
      password: 'x',
      ...(overrides.pool ?? {}),
    },
    wallet: {
      address: VALID_XMR_WALLET,
      payment_id: '',
      ...(overrides.wallet ?? {}),
    },
    server: {
      public_url: 'http://192.168.1.5:8080',
      stats_retention_hours: 168,
      build_retention_days: 30,
      pool_reconnect_seconds: 30,
      websocket_ping_seconds: 30,
      max_agents: 256,
      max_build_size_mb: 150,
      log_agent_connections: true,
      log_share_submissions: false,
      log_pool_traffic: false,
      strict_wallet_validation: false,
      dashboard_subtitle: 'security is just an emotion',
      open_firewall_on_start: true,
      obfuscate_default: false,
      sign_enabled: false,
      ...(overrides.server ?? {}),
    },
    alerts: {
      offline_threshold_minutes: 5,
      hashrate_drop_threshold_pct: 50,
      rejection_rate_threshold_pct: 5,
      ...(overrides.alerts ?? {}),
    },
    ...overrides,
  };
}

export function mockAgent(overrides: Partial<Agent> = {}): Agent {
  return {
    id: 'agent-001-uuid',
    name: 'Test Miner',
    wallet: '4' + 'A'.repeat(94),
    ip: '192.168.1.10',
    version: '1.0.0',
    status: 'online',
    cpu_cores: 8,
    memory_gb: 16,
    last_seen: new Date().toISOString(),
    created_at: new Date().toISOString(),
    hashrate_15s: 500,
    hashrate_1m: 480,
    hashrate_15m: 450,
    shares_total: 100,
    shares_good: 95,
    shares_bad: 5,
    cpu_usage_pct: 42,
    memory_usage_pct: 55,
    uptime_seconds: 3600,
    platform: 'linux',
    arch: 'amd64',
    ...overrides,
  };
}

export function mockShare(overrides: Partial<Share> = {}): Share {
  return {
    id: 1,
    agent_id: 'agent-001-uuid',
    job_id: 'job-1',
    difficulty: 1000,
    accepted: true,
    hash: 'abc123deadbeef',
    nonce: '0001',
    timestamp: new Date().toISOString(),
    ...overrides,
  };
}

export const mockServerInfo: ServerInfo = {
  port: 8080,
  host: '0.0.0.0',
  local_ips: ['192.168.1.5'],
  suggested_url: 'http://192.168.1.5:8080',
  dashboard_url: 'http://192.168.1.5:8080/dashboard',
  websocket_url: 'ws://192.168.1.5:8080/ws/dashboard',
};
