import { Result, ValueObject } from '@modules/shared';

interface PlatformFeeProps {
  amountVND: bigint;
}

/** Platform fee charged on an order (typically 5% of order amount). */
export class PlatformFee extends ValueObject<PlatformFeeProps> {
  static readonly DEFAULT_RATE = 5n; // 5%

  get value(): bigint {
    return this.props.amountVND;
  }

  /** Calculate platform fee at the default rate (5%). */
  static fromOrderAmount(orderAmountVND: bigint): Result<PlatformFee, string> {
    if (orderAmountVND <= 0n) {
      return Result.err('Số tiền đơn hàng phải lớn hơn 0');
    }
    const fee = (orderAmountVND * PlatformFee.DEFAULT_RATE) / 100n;
    return Result.ok(new PlatformFee({ amountVND: fee }));
  }

  /** Create with explicit fee amount. */
  static create(amountVND: bigint): Result<PlatformFee, string> {
    if (amountVND < 0n) {
      return Result.err('Phí nền tảng không được âm');
    }
    return Result.ok(new PlatformFee({ amountVND }));
  }
}
