import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TransactionType } from 'src/transactions/entitites/transaction-type.entity';
import { TransactionTypeEnum } from 'src/transactions/transaction-type.enum';
import { Repository } from 'typeorm';

@Injectable()
export class TransactionsTypeSeedService {
  constructor(
    @InjectRepository(TransactionType)
    private repository: Repository<TransactionType>,
  ) {}

  async run() {
    const count = await this.repository.count();

    if (count === 0) {
      await this.repository.save([
        this.repository.create({
          id: TransactionTypeEnum.credit,
          name: 'credit',
        }),
        this.repository.create({
          id: TransactionTypeEnum.fee,
          name: 'fee',
        }),
        this.repository.create({
          id: TransactionTypeEnum.fine,
          name: 'fine',
        }),
        this.repository.create({
          id: TransactionTypeEnum.levy,
          name: 'levy',
        }),
        this.repository.create({
          id: TransactionTypeEnum.payment,
          name: 'payment',
        }),
      ]);
    }
  }
}
