import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TeamWalletTransaction } from 'src/team-wallet-transactions/entities/team-wallet-transaction.entity';
import { TeamWalletTransactionEnum } from 'src/team-wallet-transactions/team-wallet-transaction.enum';
import { Team } from 'src/teams/entities/team.entity';
import { Repository } from 'typeorm';
import { faker } from '@faker-js/faker';

@Injectable()
export class TeamWalletTransactionSeedService {
  constructor(
    @InjectRepository(TeamWalletTransaction)
    private repository: Repository<TeamWalletTransaction>,
    @InjectRepository(Team)
    private teamrepository: Repository<Team>,
  ) {}

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

    if (amount === 0) {
      const team = await this.teamrepository.findOneBy({ id: 1 });

      for (let index = 0; index < 20; index++) {
        await this.repository.save(
          this.repository.create({
            team: team,
            note: '',
            date: faker.date.recent(90).toISOString(),
            amount: Math.random() * 10,
            type: {
              id: TeamWalletTransactionEnum.credit,
              name: 'credit',
            },
          }),
        );
      }
    }
  }
}
