import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TeamWalletTransactionType } from 'src/team-wallet-transactions/entities/team-wallet-transaction-type.entity';
import { TeamWalletTransactionEnum } from 'src/team-wallet-transactions/team-wallet-transaction.enum';
import { Repository } from 'typeorm';

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

  async run() {
    const amount = await this.repository.count({
      where: {
        id: 0,
      },
    });

    if (amount === 0) {
      await this.repository.save(
        this.repository.create({
          id: TeamWalletTransactionEnum.credit,
          name: 'credit',
        }),
      );

      await this.repository.save(
        this.repository.create({
          id: TeamWalletTransactionEnum.expense,
          name: 'expense',
        }),
      );
    }
  }
}
