import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';

// Controllers
import { PrePlantingController } from './api/controllers/pre-planting.controller';
import { InternalPrePlantingController } from './api/controllers/internal-pre-planting.controller';
import { PrePlantingPublicController } from './api/controllers/pre-planting-public.controller';

// Application Services
import { PrePlantingApplicationService } from './application/services/pre-planting-application.service';
import { PrePlantingRewardService } from './application/services/pre-planting-reward.service';

// Repositories
import { PrePlantingOrderRepository } from './infrastructure/repositories/pre-planting-order.repository';
import { PrePlantingPositionRepository } from './infrastructure/repositories/pre-planting-position.repository';
import { PrePlantingMergeRepository } from './infrastructure/repositories/pre-planting-merge.repository';
import { PrePlantingRewardEntryRepository } from './infrastructure/repositories/pre-planting-reward-entry.repository';

// External Clients
import { PrePlantingAdminClient } from './infrastructure/external/pre-planting-admin.client';
import { PrePlantingReferralClient } from './infrastructure/external/pre-planting-referral.client';
import { PrePlantingAuthorizationClient } from './infrastructure/external/pre-planting-authorization.client';

/**
 * 预种计划模块 (预种计划 / 拼种团购计划)
 *
 * === 功能概述 ===
 * [2026-03-01] 方案调整：1887 USDT/份 × 10 份 = 18870 USDT/棵（原 3566 × 5 = 17830）
 * 用户以 1887 USDT/份 参与认种（1棵树的1/10价格），累计10份自动合成1棵树，
 * 触发合同签署和挖矿开启，同时解除交易和提现限制。
 *
 * === 架构设计 ===
 * - 完全独立的 NestJS Module，与现有 PlantingOrder 聚合根零耦合
 * - 拥有自己的聚合根：PrePlantingOrder、PrePlantingPosition、PrePlantingMerge
 * - 拥有自己的 Prisma 表：pre_planting_orders、pre_planting_positions、
 *   pre_planting_merges、pre_planting_reward_entries
 * - 拥有自己的 Kafka Topic：pre-planting.portion.purchased、pre-planting.merged、
 *   pre-planting.contract.signed（不复用任何现有 Topic）
 *
 * === 跨服务调用 ===
 * - wallet-service: 冻结/确认扣款/分配资金（复用已有内部 API）
 * - referral-service: 获取推荐人信息（GET /api/v1/referrals/:seq/chain）
 * - authorization-service: 获取社区/省/市权益分配对象
 * - admin-service: 获取预种开关状态
 *
 * === 对现有系统的影响 ===
 * - 零侵入：不创建 PlantingOrder → 现有 referral/reward/contract 流程完全不受触发
 * - 不发布 planting.planting.created → 现有消费者无感知
 * - 通过 InfrastructureModule (@Global) 注入共享依赖
 */
@Module({
  imports: [
    HttpModule.register({
      timeout: 5000,
      maxRedirects: 5,
    }),
  ],
  controllers: [
    PrePlantingController,
    PrePlantingPublicController,
    InternalPrePlantingController,
  ],
  providers: [
    // Application Services
    PrePlantingApplicationService,
    PrePlantingRewardService,

    // Repositories
    PrePlantingOrderRepository,
    PrePlantingPositionRepository,
    PrePlantingMergeRepository,
    PrePlantingRewardEntryRepository,

    // External Clients
    PrePlantingAdminClient,
    PrePlantingReferralClient,
    PrePlantingAuthorizationClient,
  ],
  exports: [PrePlantingApplicationService],
})
export class PrePlantingModule {}
