import { Inject, Injectable } from '@nestjs/common';
import { OfacScreening } from '../../domain/entities/ofac-screening.entity';
import {
  OFAC_SCREENING_REPOSITORY,
  IOfacScreeningRepository,
} from '../../domain/repositories/ofac-screening.repository.interface';

@Injectable()
export class OfacService {
  constructor(
    @Inject(OFAC_SCREENING_REPOSITORY)
    private readonly repo: IOfacScreeningRepository,
  ) {}

  /**
   * Screen a name against OFAC SDN list (mock implementation).
   * In production, calls Chainalysis or similar API.
   */
  async screenName(userId: string, name: string): Promise<OfacScreening> {
    // Mock: no matches in dev
    const screening = this.repo.create({
      userId,
      screenedName: name,
      matchScore: '0',
      isMatch: false,
      result: 'clear',
      details: { source: 'mock', checkedAt: new Date().toISOString() },
    });
    return this.repo.save(screening);
  }

  async getScreeningsByUserId(userId: string) {
    return this.repo.findByUserId(userId);
  }
}
