import { Injectable } from '@nestjs/common';

/**
 * 转让费用计算领域服务
 */
@Injectable()
export class TransferFeeDomainService {
  /**
   * 平台手续费率：2%
   */
  private readonly PLATFORM_FEE_RATE = '0.0200';

  /**
   * 计算转让费用
   */
  calculateFees(transferPrice: string): {
    platformFeeRate: string;
    platformFeeAmount: string;
    sellerReceiveAmount: string;
  } {
    const price = parseFloat(transferPrice);
    const feeRate = parseFloat(this.PLATFORM_FEE_RATE);
    const feeAmount = Math.round(price * feeRate * 100000000) / 100000000;
    const sellerReceive = Math.round((price - feeAmount) * 100000000) / 100000000;

    return {
      platformFeeRate: this.PLATFORM_FEE_RATE,
      platformFeeAmount: feeAmount.toFixed(8),
      sellerReceiveAmount: sellerReceive.toFixed(8),
    };
  }
}
