import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TeamSetting } from 'src/team-settings/entities/team-setting.entity';
import { Team } from 'src/teams/entities/team.entity';
import { Repository } from 'typeorm';

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

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

    if (countTeamSettings === 0) {
      const team = await this.teamrepository.findOne({ where: { id: 1 } });
      await this.repository.save(
        this.repository.create({
          team,
          key: 'transaction_create_min_role',
          value: '2',
        }),
      );
    }
  }
}
