import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
  DeleteDateColumn,
  UpdateDateColumn,
  OneToMany,
  Index,
} from "typeorm"
import { State } from "src/modules/state/entities/state.entity"
import { Country } from "src/modules/country/entities/country.entity"
import { Address } from "src/modules/team-member/entities/address.entity"
import { Hospital } from "src/modules/hospitals/entities/hospital.entity"
import { Customer } from "src/modules/customers/entities/customer.entity"
import { VehiclePricing } from "src/modules/vehicle-pricing/entities/vehicle-pricing.entity"
import { AddOnsPricing } from "src/modules/add-ons-pricing/entities/add-ons-pricing.entity"
import { ServicePricing } from "src/modules/service-pricing/entities/service-pricing.entity"
import { Trip } from "src/modules/trips/entities/trip.entity"
import { TeamMember } from "src/modules/team-member/entities/team_member.entity"
import { FleetManagement } from "src/modules/fleet-management/entities/fleet-management.entity"

@Entity("cities")
export class City {
  @PrimaryGeneratedColumn()
  @Index()
  id: number

  @Column({ type: "varchar", nullable: false })
  @Index()
  name: string

  @Column({ type: "int" })
  state_id: number

  @Column({ type: "int" })
  country_id: number

  @DeleteDateColumn()
  deleted_at: Date

  @CreateDateColumn({ type: "timestamp", default: () => "NOW()" })
  created_at: Date

  @UpdateDateColumn({ type: "timestamp", default: () => "NOW()" })
  updated_at: Date

  @ManyToOne(() => State, (state) => state.cities, { onDelete: "RESTRICT" })
  @JoinColumn({ name: "state_id" })
  state: State

  @ManyToOne(() => Country, (country) => country.cities, {
    onDelete: "RESTRICT",
  })
  @JoinColumn({ name: "country_id" })
  country: Country

  @OneToMany(() => Address, (address: Address) => address.city)
  addresses: Address[]

  @OneToMany(() => Hospital, (hospital) => hospital.city)
  hospitals: Hospital[]

  @OneToMany(() => Customer, (customer) => customer.city)
  customer: Customer[]

  @OneToMany(() => Customer, (customer) => customer.pricing_city)
  pricing_customers: Customer[]

  @OneToMany(() => VehiclePricing, (vehicle_pricing) => vehicle_pricing.city)
  vehicle_pricing: VehiclePricing[]

  @OneToMany(() => AddOnsPricing, (add_ons_pricing) => add_ons_pricing.city)
  add_ons_pricing: AddOnsPricing[]

  @OneToMany(() => ServicePricing, (service_pricing) => service_pricing.city)
  service_pricing: ServicePricing[]

  @OneToMany(() => Trip, (trips) => trips.city)
  trips: Trip[]

  @OneToMany(() => TeamMember, (team_member) => team_member.city)
  team_member: TeamMember[]

  @OneToMany(
    () => FleetManagement,
    (location) => location.vehicle_city_location,
  )
  fleet_location: FleetManagement[]
}
