import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { TravelRuleRecord } from '../../domain/entities/travel-rule-record.entity';
import { ITravelRuleRepository } from '../../domain/repositories/travel-rule.repository.interface';

@Injectable()
export class TravelRuleRepository implements ITravelRuleRepository {
  constructor(
    @InjectRepository(TravelRuleRecord)
    private readonly repo: Repository<TravelRuleRecord>,
  ) {}

  create(data: Partial<TravelRuleRecord>): TravelRuleRecord {
    return this.repo.create(data);
  }

  async save(record: TravelRuleRecord): Promise<TravelRuleRecord> {
    return this.repo.save(record);
  }

  async findByTransactionId(transactionId: string): Promise<TravelRuleRecord | null> {
    return this.repo.findOne({ where: { transactionId } });
  }

  async count(): Promise<number> {
    return this.repo.count();
  }
}
