// Commodities Engine

import prisma from '@/shared/database/prisma';
import { Decimal } from '@prisma/client/runtime/library';
import { subLedgerService } from '@/core/ledger/subledgers/subledger.service';


export class CommoditiesService {
  /**
   * Update commodity spot price
   */
  async updateSpotPrice(
    commodityType: string,
    unit: string,
    spotPrice: string,
    priceSource: string
  ): Promise<void> {
    // TODO: Store spot price in a separate pricing table or external service
    // For now, log the price update (spotPrice field doesn't exist in schema)
    const { logger } = await import('@/infrastructure/monitoring/logger');
    logger.info('Commodity spot price update', {
      commodityType,
      unit,
      spotPrice,
      priceSource,
    });
    // Note: spotPrice is not stored in commodity_digital_tokens schema
    // Consider creating a separate pricing table or using external pricing service
  }

  /**
   * Create commodity sub-ledger entry
   */
  async createCommodityEntry(
    ledgerEntryId: string,
    commodityType: string,
    quantity: string,
    unit: string,
    price?: string
  ): Promise<void> {
    await subLedgerService.createCommoditiesSubLedgerEntry(
      ledgerEntryId,
      commodityType,
      quantity,
      unit,
      price
    );
  }
}

export const commoditiesService = new CommoditiesService();

