import { Inject, Injectable } from '@nestjs/common';
import {
  SAR_REPORT_REPOSITORY,
  ISarReportRepository,
} from '../../domain/repositories/sar-report.repository.interface';

@Injectable()
export class SarService {
  constructor(
    @Inject(SAR_REPORT_REPOSITORY)
    private readonly repo: ISarReportRepository,
  ) {}

  async createReport(data: {
    alertId: string;
    userId: string;
    reportType: string;
    narrative: string;
  }) {
    const report = this.repo.create({ ...data, filingStatus: 'draft' });
    return this.repo.save(report);
  }

  async fileReport(id: string) {
    await this.repo.update(id, {
      filingStatus: 'filed',
      filedAt: new Date(),
      fincenReference: `FINCEN-${Date.now()}`,
    });
  }

  async listReports(page: number, limit: number) {
    const [items, total] = await this.repo.findPaginated(page, limit);
    return { items, total, page, limit };
  }
}
