import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { State } from 'src/state/entities/state.entity';
import { StateService } from 'src/state/state.service';
import { Repository } from 'typeorm';
import * as data from './states.json';

@Injectable()
export class DatabaseSeederService implements OnModuleInit {
  constructor(
    @InjectRepository(State) private stateRepo: Repository<State>,
    private readonly stateService: StateService,
  ) {}

  async insertStates() {
    const states = data.states;
    for (const state of states) {
      await this.stateService.create(state);
    }
  }

  async onModuleInit() {
    await this.insertStates();
  }
}
