// API 端点定义
// 注意: baseURL 是 https://api.rwadurian.com/api，Kong 路由前缀是 /api/v1/
// 所以这里的端点需要以 /v1/ 开头

export const API_ENDPOINTS = {
  // 认证 (identity-service)
  AUTH: {
    LOGIN: '/v1/auth/login',
    LOGOUT: '/v1/auth/logout',
    REFRESH: '/v1/auth/refresh',
    FORGOT_PASSWORD: '/v1/auth/forgot-password',
    REGISTER: '/v1/auth/register',
  },

  // 用户管理 (admin-service)
  // 注意：系统不允许管理员修改用户数据，用户数据只能由用户本人修改
  USERS: {
    LIST: '/v1/admin/users',
    DETAIL: (id: string) => `/v1/admin/users/${id}`,
    STATS: '/v1/admin/users/stats/summary',
    EXPORT: '/v1/admin/users/export',
  },

  // 用户详情页面 (admin-service) - 完整用户信息、推荐关系、分类账等
  USER_DETAIL: {
    FULL_DETAIL: (accountSequence: string) => `/v1/admin/users/${accountSequence}/full-detail`,
    REFERRAL_TREE: (accountSequence: string) => `/v1/admin/users/${accountSequence}/referral-tree`,
    PLANTING_LEDGER: (accountSequence: string) => `/v1/admin/users/${accountSequence}/planting-ledger`,
    WALLET_LEDGER: (accountSequence: string) => `/v1/admin/users/${accountSequence}/wallet-ledger`,
    AUTHORIZATION_DETAIL: (accountSequence: string) => `/v1/admin/users/${accountSequence}/authorization-detail`,
  },

  // 龙虎榜 (leaderboard-service)
  LEADERBOARD: {
    RANKINGS: '/v1/leaderboard/rankings',
    DAILY: '/v1/leaderboard/daily',
    WEEKLY: '/v1/leaderboard/weekly',
    MONTHLY: '/v1/leaderboard/monthly',
    SETTINGS: '/v1/leaderboard/settings',
    EXPORT: '/v1/leaderboard/export',
    // 配置管理
    CONFIG: '/v1/leaderboard/config',
    CONFIG_SWITCH: '/v1/leaderboard/config/switch',
    CONFIG_VIRTUAL: '/v1/leaderboard/config/virtual',
    CONFIG_DISPLAY: '/v1/leaderboard/config/display',
  },

  // 授权管理 (authorization-service)
  AUTHORIZATION: {
    // 管理员授权管理
    ADMIN_LIST: '/v1/admin/authorizations',
    ADMIN_REVOKE: (id: string) => `/v1/admin/authorizations/${id}/revoke`,
    ADMIN_GRANT_COMMUNITY: '/v1/admin/authorizations/community',
    ADMIN_GRANT_PROVINCE_COMPANY: '/v1/admin/authorizations/province-company',
    ADMIN_GRANT_CITY_COMPANY: '/v1/admin/authorizations/city-company',
    ADMIN_GRANT_AUTH_PROVINCE_COMPANY: '/v1/admin/authorizations/auth-province-company',
    ADMIN_GRANT_AUTH_CITY_COMPANY: '/v1/admin/authorizations/auth-city-company',
    // [2026-03-02] 纯新增：自助申请照片（绕过 CDC，读源头数据）
    SELF_APPLY_PHOTOS: '/v1/admin/authorization-photos',
    // 其他授权端点
    PROVINCE_COMPANIES: '/v1/authorizations/province-companies',
    CITY_COMPANIES: '/v1/authorizations/city-companies',
    PROVINCE_RULES: '/v1/authorizations/province-rules',
    CITY_RULES: '/v1/authorizations/city-rules',
    ASSESSMENT_RULES: '/v1/authorizations/assessment-rules',
    LADDER_TARGETS: '/v1/authorizations/ladder-targets',
    LIMITS: '/v1/authorizations/limits',
    AUTHORIZE: (id: string) => `/v1/authorizations/${id}/authorize`,
    REVOKE: (id: string) => `/v1/authorizations/${id}/revoke`,
  },

  // 数据统计 (reporting-service)
  STATISTICS: {
    OVERVIEW: '/v1/reports/overview',
    TREND: '/v1/reports/trend',
    REGION: '/v1/reports/region',
    REGION_PROVINCE: '/v1/reports/region/province',
    REGION_CITY: '/v1/reports/region/city',
    LEADERBOARD: '/v1/reports/leaderboard',
    OPERATIONS: '/v1/reports/operations',
    REVENUE: '/v1/reports/revenue',
    EXPORT: '/v1/export',
  },

  // 系统设置 (admin-service)
  SETTINGS: {
    ALL: '/v1/admin/settings',
    SETTLEMENT: '/v1/admin/settings/settlement',
    LEADERBOARD: '/v1/admin/settings/leaderboard',
    QUOTA: '/v1/admin/settings/quota',
    ASSESSMENT: '/v1/admin/settings/assessment',
    DISPLAY: '/v1/admin/settings/display',
    SECURITY: '/v1/admin/settings/security',
    ACCOUNTS: '/v1/admin/settings/accounts',
    OPERATION_LOGS: '/v1/admin/settings/operation-logs',
  },

  // 系统配置 (admin-service)
  SYSTEM_CONFIG: {
    ALL: '/v1/admin/system-config',
    DISPLAY_SETTINGS: '/v1/admin/system-config/display/settings',
    BY_KEY: (key: string) => `/v1/admin/system-config/${key}`,
  },

  // 帮助中心
  HELP: {
    DOCUMENTS: '/v1/help/documents',
    DOCUMENT_DETAIL: (id: string) => `/v1/help/documents/${id}`,
    FAQ: '/v1/help/faq',
    SEARCH: '/v1/help/search',
    FEEDBACK: '/v1/help/feedback',
  },

  // 仪表板 (reporting-service)
  DASHBOARD: {
    OVERVIEW: '/v1/dashboard/overview',
    STATS: '/v1/dashboard/stats',
    ACTIVITIES: '/v1/dashboard/activities',
    CHARTS: '/v1/dashboard/charts',
    REGION: '/v1/dashboard/region',
    // [2026-01-07] 新增：热钱包余额
    HOT_WALLET_BALANCE: '/v1/dashboard/hot-wallet-balance',
  },

  // 认种统计 (planting-service) - 从订单表实时聚合，数据可靠
  PLANTING_STATS: {
    GLOBAL: '/v1/planting/stats/global',
    // [2026-01-06] 新增：趋势数据接口
    TREND: '/v1/planting/stats/trend',
  },

  // 通知管理 (admin-service)
  NOTIFICATIONS: {
    LIST: '/v1/admin/notifications',
    CREATE: '/v1/admin/notifications',
    DETAIL: (id: string) => `/v1/admin/notifications/${id}`,
    UPDATE: (id: string) => `/v1/admin/notifications/${id}`,
    DELETE: (id: string) => `/v1/admin/notifications/${id}`,
  },

  // 用户画像 - 标签管理 (admin-service)
  USER_TAGS: {
    // 标签分类
    CATEGORIES: '/v1/admin/tags/categories',
    CATEGORY_DETAIL: (id: string) => `/v1/admin/tags/categories/${id}`,
    // 标签
    LIST: '/v1/admin/tags',
    CREATE: '/v1/admin/tags',
    DETAIL: (id: string) => `/v1/admin/tags/${id}`,
    UPDATE: (id: string) => `/v1/admin/tags/${id}`,
    DELETE: (id: string) => `/v1/admin/tags/${id}`,
    ESTIMATE_USERS: (id: string) => `/v1/admin/tags/${id}/estimate-users`,
    // 用户标签分配
    ASSIGN: '/v1/admin/tags/assign',
    BATCH_ASSIGN: '/v1/admin/tags/batch-assign',
    REMOVE: '/v1/admin/tags/remove',
    USER_TAGS: (accountSequence: string) => `/v1/admin/tags/user/${accountSequence}`,
    TAG_USERS: (tagId: string) => `/v1/admin/tags/${tagId}/users`,
  },

  // 用户画像 - 分类规则 (admin-service)
  CLASSIFICATION_RULES: {
    LIST: '/v1/admin/rules',
    CREATE: '/v1/admin/rules',
    DETAIL: (id: string) => `/v1/admin/rules/${id}`,
    UPDATE: (id: string) => `/v1/admin/rules/${id}`,
    DELETE: (id: string) => `/v1/admin/rules/${id}`,
    EVALUATE: (id: string) => `/v1/admin/rules/${id}/evaluate`,
  },

  // 用户画像 - 人群包 (admin-service)
  AUDIENCE_SEGMENTS: {
    LIST: '/v1/admin/segments',
    CREATE: '/v1/admin/segments',
    DETAIL: (id: string) => `/v1/admin/segments/${id}`,
    UPDATE: (id: string) => `/v1/admin/segments/${id}`,
    DELETE: (id: string) => `/v1/admin/segments/${id}`,
    REFRESH: (id: string) => `/v1/admin/segments/${id}/refresh`,
  },

  // 共管钱包 (admin-service)
  CO_MANAGED_WALLETS: {
    LIST: '/v1/admin/co-managed-wallets',
    CREATE_SESSION: '/v1/admin/co-managed-wallets/sessions',
    SESSION_DETAIL: (sessionId: string) => `/v1/admin/co-managed-wallets/sessions/${sessionId}`,
    WALLET_DETAIL: (walletId: string) => `/v1/admin/co-managed-wallets/${walletId}`,
  },

  // 系统维护 (admin-service)
  MAINTENANCE: {
    LIST: '/v1/admin/maintenance',
    CREATE: '/v1/admin/maintenance',
    DETAIL: (id: string) => `/v1/admin/maintenance/${id}`,
    UPDATE: (id: string) => `/v1/admin/maintenance/${id}`,
    TOGGLE: (id: string) => `/v1/admin/maintenance/${id}/toggle`,
    DELETE: (id: string) => `/v1/admin/maintenance/${id}`,
    CURRENT_STATUS: '/v1/admin/maintenance/status/current',
  },

  // 用户待办操作 (identity-service)
  PENDING_ACTIONS: {
    LIST: '/v1/admin/pending-actions',
    CREATE: '/v1/admin/pending-actions',
    BATCH_CREATE: '/v1/admin/pending-actions/batch',
    DETAIL: (id: string) => `/v1/admin/pending-actions/${id}`,
    UPDATE: (id: string) => `/v1/admin/pending-actions/${id}`,
    CANCEL: (id: string) => `/v1/admin/pending-actions/${id}/cancel`,
    DELETE: (id: string) => `/v1/admin/pending-actions/${id}`,
  },

  // 法币提现审核 (wallet-service)
  FIAT_WITHDRAWALS: {
    PENDING_REVIEW: '/v1/wallets/fiat-withdrawals/pending-review',
    PENDING_PAYMENT: '/v1/wallets/fiat-withdrawals/pending-payment',
    BY_STATUS: '/v1/wallets/fiat-withdrawals/by-status',
    REVIEW: (orderNo: string) => `/v1/wallets/fiat-withdrawals/${orderNo}/review`,
    START_PAYMENT: (orderNo: string) => `/v1/wallets/fiat-withdrawals/${orderNo}/start-payment`,
    COMPLETE_PAYMENT: (orderNo: string) => `/v1/wallets/fiat-withdrawals/${orderNo}/complete-payment`,
  },

  // [2026-01-06] 新增：系统账户划转 (wallet-service)
  // [2026-01-07] 修复：ACCOUNT_NAME 改为基础路径，通过 query 参数传递 accountSequence
  SYSTEM_WITHDRAWAL: {
    // 发起划转请求
    REQUEST: '/v1/wallets/system-withdrawal/request',
    // 获取可划转账户列表
    ACCOUNTS: '/v1/wallets/system-withdrawal/accounts',
    // 查询划转订单
    ORDERS: '/v1/wallets/system-withdrawal/orders',
    // 获取账户名称（通过 query 参数 ?accountSequence=xxx）
    ACCOUNT_NAME: '/v1/wallets/system-withdrawal/account-name',
  },

  // [2026-01-04] 新增：系统账户报表 (reporting-service)
  // 回滚方式：删除此部分即可
  SYSTEM_ACCOUNT_REPORTS: {
    FULL_REPORT: '/v1/system-account-reports',
    FIXED_ACCOUNTS: '/v1/system-account-reports/fixed-accounts',
    PROVINCE_SUMMARY: '/v1/system-account-reports/province-summary',
    CITY_SUMMARY: '/v1/system-account-reports/city-summary',
    OFFLINE_SETTLEMENT: '/v1/system-account-reports/offline-settlement',
    EXPIRED_REWARDS: '/v1/system-account-reports/expired-rewards',
    // [2026-01-05] 新增：所有系统账户分类账明细
    ALL_LEDGER: '/v1/system-account-reports/all-ledger',
    // [2026-01-06] 新增：收益类型汇总统计（系统费用：成本费、运营费等）
    REWARD_TYPE_SUMMARIES: '/v1/system-account-reports/reward-type-summaries',
    // [2026-01-06] 新增：收益类型详细记录列表
    REWARD_ENTRIES_BY_TYPE: '/v1/system-account-reports/reward-entries-by-type',
    FEE_ENTRIES_DETAILED: '/v1/system-account-reports/fee-entries-detailed',
    // [2026-01-06] 新增：手续费归集账户统计（真正的提现手续费）
    FEE_COLLECTION_SUMMARY: '/v1/system-account-reports/fee-collection-summary',
    FEE_COLLECTION_ENTRIES: '/v1/system-account-reports/fee-collection-entries',
    // [2026-01-07] 新增：面对面结算明细列表
    OFFLINE_SETTLEMENT_ENTRIES: '/v1/system-account-reports/offline-settlement-entries',
    // [2026-01-07] 新增：过期收益明细列表
    EXPIRED_REWARDS_ENTRIES: '/v1/system-account-reports/expired-rewards-entries',
  },

  // 应用图片资源管理 (admin-service)
  APP_ASSETS: {
    LIST: '/v1/admin/app-assets',
    UPLOAD: '/v1/admin/app-assets/upload',
    UPDATE: (id: string) => `/v1/admin/app-assets/${id}`,
    DELETE: (id: string) => `/v1/admin/app-assets/${id}`,
  },

  // 客服联系方式管理 (admin-service)
  CUSTOMER_SERVICE_CONTACTS: {
    LIST: '/v1/admin/customer-service-contacts',
    CREATE: '/v1/admin/customer-service-contacts',
    UPDATE: (id: string) => `/v1/admin/customer-service-contacts/${id}`,
    DELETE: (id: string) => `/v1/admin/customer-service-contacts/${id}`,
  },

  // [2026-02-05] 新增：合同管理 (admin-service)
  // 回滚方式：删除此部分即可
  CONTRACTS: {
    // 合同列表查询
    LIST: '/v1/admin/contracts',
    // 合同统计信息
    STATISTICS: '/v1/admin/contracts/statistics',
    // 合同详情
    DETAIL: (orderNo: string) => `/v1/admin/contracts/${orderNo}`,
    // 下载合同 PDF（支持断点续传）
    DOWNLOAD: (orderNo: string) => `/v1/admin/contracts/${orderNo}/download`,
    // 用户合同列表
    USER_CONTRACTS: (accountSequence: string) => `/v1/admin/contracts/users/${accountSequence}`,
    // 批量下载任务
    BATCH_DOWNLOAD: '/v1/admin/contracts/batch-download',
    // 批量下载任务状态
    BATCH_DOWNLOAD_STATUS: (taskNo: string) => `/v1/admin/contracts/batch-download/${taskNo}`,
  },
  // [2026-02-17] 新增：预种计划管理 (admin-service / PrePlantingAdminModule)
  // 3566 USDT/份预种，累计 5 份合成 1 棵树
  // 开关管理 + 预种订单/持仓/合并记录查询
  PRE_PLANTING: {
    // 预种开关配置
    CONFIG: '/v1/admin/pre-planting/config',
    TOGGLE: '/v1/admin/pre-planting/config/toggle',
    // 预种订单列表（管理员视角，可按用户/状态过滤）
    ORDERS: '/v1/admin/pre-planting/orders',
    // 预种持仓列表（管理员视角）
    POSITIONS: '/v1/admin/pre-planting/positions',
    // 合并记录列表（管理员视角）
    MERGES: '/v1/admin/pre-planting/merges',
    // 预种统计汇总（总份数、总金额、合并树数等）
    STATS: '/v1/admin/pre-planting/stats',
    // [2026-02-28] 预种协议文本（管理员可编辑）
    AGREEMENT: '/v1/admin/pre-planting/agreement',
  },
  // [2026-02-19] 纯新增：树转让管理 (transfer-service)
  // Saga 编排的树转让订单管理：列表/详情/统计/强制取消
  TRANSFERS: {
    LIST: '/v1/admin/transfers',
    DETAIL: (no: string) => `/v1/admin/transfers/${no}`,
    STATS: '/v1/admin/transfers/stats',
    FORCE_CANCEL: (no: string) => `/v1/admin/transfers/${no}/force-cancel`,
  },
  // [2026-02-26] 新增：认种树定价配置 (admin-service / TreePricingModule)
  // 总部运营成本压力涨价管理：手动调价 + 自动涨价 + 审计日志
  TREE_PRICING: {
    CONFIG: '/v1/admin/tree-pricing/config',
    SUPPLEMENT: '/v1/admin/tree-pricing/supplement',
    AUTO_INCREASE: '/v1/admin/tree-pricing/auto-increase',
    CHANGE_LOG: '/v1/admin/tree-pricing/change-log',
  },
} as const;
