import { Injectable } from "@nestjs/common"
import { defaultTripType } from "../../../config/app.config"
import { TripsService } from "src/modules/trips/v1/trips.service"
import { TripType } from "src/modules/trips/entities/trip-type.entity"

@Injectable()
export class TripTypeSeedService {
  constructor(private readonly tripsService: TripsService) {}

  async run() {
    try {
      for (const defaultData of defaultTripType) {
        const isTripTypeMissing = await this.tripsService.isTripTypeExist(
          defaultData.name,
        )

        if (isTripTypeMissing) {
          const newTripType = new TripType()
          Object.assign(newTripType, defaultData)

          await this.tripsService.createTripType(newTripType)
          console.log("Trip type seeded successfully!")
        } else {
          console.log("Trip type seeding skipped.")
        }
      }
    } catch (error) {
      console.error("Error running Trip type seeder:", error)
    }
  }
}
