import { Injectable } from "@nestjs/common"
import { defaultTripIncidentType } from "../../../config/app.config"
import { IncidentReportingService } from "src/modules/incident-reporting/v1/incident-reporting.service"
import { IncidentType } from "src/modules/incident-reporting/entities/incident-type.entity"

@Injectable()
export class IncidentTypeSeedService {
  constructor(
    private readonly incidentReportingService: IncidentReportingService,
  ) {}

  async run() {
    try {
      for (const incidentType of defaultTripIncidentType) {
        const isExitIncidentType =
          await this.incidentReportingService.checkIncidentExist(
            incidentType?.name,
          )

        if (isExitIncidentType) {
          const newIncidentType = new IncidentType()
          newIncidentType.name = incidentType.name

          await this.incidentReportingService.createIncidentType(
            newIncidentType,
          )

          console.log("Incident type seeded successfully!")
        } else {
          console.log("Incident type seeding skipped.")
        }
      }
    } catch (error) {
      console.error("Error running Incident type seeder:", error)
    }
  }
}
