import { RewardSummary as PrismaRewardSummary, Prisma } from '@prisma/client';
import { RewardSummary } from '../../../domain/aggregates/reward-summary/reward-summary.aggregate';

export class RewardSummaryMapper {
  static toDomain(raw: PrismaRewardSummary): RewardSummary {
    return RewardSummary.reconstitute({
      id: raw.id,
      userId: raw.userId,
      accountSequence: raw.accountSequence,
      pendingUsdt: Number(raw.pendingUsdt),
      pendingHashpower: Number(raw.pendingHashpower),
      pendingExpireAt: raw.pendingExpireAt,
      settleableUsdt: Number(raw.settleableUsdt),
      settleableHashpower: Number(raw.settleableHashpower),
      settledTotalUsdt: Number(raw.settledTotalUsdt),
      settledTotalHashpower: Number(raw.settledTotalHashpower),
      expiredTotalUsdt: Number(raw.expiredTotalUsdt),
      expiredTotalHashpower: Number(raw.expiredTotalHashpower),
      lastUpdateAt: raw.lastUpdateAt,
      createdAt: raw.createdAt,
    });
  }

  static toPersistence(summary: RewardSummary) {
    return {
      id: summary.id || undefined,
      userId: summary.userId,
      accountSequence: summary.accountSequence,
      pendingUsdt: new Prisma.Decimal(summary.pendingUsdt.amount),
      pendingHashpower: new Prisma.Decimal(summary.pendingHashpower.value),
      pendingExpireAt: summary.pendingExpireAt,
      settleableUsdt: new Prisma.Decimal(summary.settleableUsdt.amount),
      settleableHashpower: new Prisma.Decimal(summary.settleableHashpower.value),
      settledTotalUsdt: new Prisma.Decimal(summary.settledTotalUsdt.amount),
      settledTotalHashpower: new Prisma.Decimal(summary.settledTotalHashpower.value),
      expiredTotalUsdt: new Prisma.Decimal(summary.expiredTotalUsdt.amount),
      expiredTotalHashpower: new Prisma.Decimal(summary.expiredTotalHashpower.value),
      lastUpdateAt: summary.lastUpdateAt,
      createdAt: summary.createdAt,
    };
  }
}
