import { Injectable } from "@nestjs/common"
import { InjectRepository } from "@nestjs/typeorm"
import { Repository } from "typeorm"
import { CancelReason } from "src/modules/cancel-reasons/entities/cancel-reasons.entity"

@Injectable()
export class CancelReasonSeedService {
  constructor(
    @InjectRepository(CancelReason)
    private repository: Repository<CancelReason>,
  ) {}

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

    if (count === 0) {
      await this.repository.save([
        // Admin Panel / Dispatcher App
        this.repository.create({
          name: "Customer Requested Cancellation",
          description: "Customer Requested Cancellation",
          type: "admin",
        }),
        this.repository.create({
          name: "Driver Unavailable/Emergency",
          description: "Driver Unavailable/Emergency",
          type: "admin",
        }),
        this.repository.create({
          name: "Vehicle Issue/Breakdown",
          description: "Vehicle Issue/Breakdown",
          type: "admin",
        }),
        this.repository.create({
          name: "External Factor",
          description: "External Factor",
          type: "admin",
        }),
        this.repository.create({
          name: "Other",
          description: "Other",
          type: "admin",
        }),

        // Driver App
        this.repository.create({
          name: "Customer Requested Cancellation",
          description: "Customer Requested Cancellation",
          type: "driver",
        }),
        this.repository.create({
          name: "Personal Emergency/Unavailable",
          description: "Personal Emergency/Unavailable",
          type: "driver",
        }),
        this.repository.create({
          name: "Vehicle Issue/Breakdown",
          description: "Vehicle Issue/Breakdown",
          type: "driver",
        }),
        this.repository.create({
          name: "External Factor",
          description: "External Factor",
          type: "driver",
        }),
        this.repository.create({
          name: "Other",
          description: "Other",
          type: "driver",
        }),

        // Customer App
        this.repository.create({
          name: "Change of plan/No longer needed",
          description: "Change of plan/No longer needed",
          type: "customer",
        }),
        this.repository.create({
          name: "Driver Delayed/Taking too long",
          description: "Driver Delayed/Taking too long",
          type: "customer",
        }),
        this.repository.create({
          name: "Personal Emergency/Urgent Situation",
          description: "Personal Emergency/Urgent Situation",
          type: "customer",
        }),
        this.repository.create({
          name: "Other",
          description: "Other",
          type: "customer",
        }),
      ])
    }
  }
}
