import {
  Column,
  CreateDateColumn,
  DeleteDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from "typeorm"
import { Customer } from "./customer.entity"
import { EpisodeLog } from "./episode_log.entity"
import { TripLog } from "src/modules/trips/entities/trip-logs.entity"

@Entity("customer_episodes")
export class CustomerEpisode {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ type: "int", nullable: false })
  customer_id: number

  @Column({ type: "int", nullable: false })
  episode_number: number

  @Column({ type: "timestamp", nullable: true })
  start_date: Date

  @Column({ type: "timestamp", nullable: true })
  end_date: Date

  @Column({ type: "varchar", nullable: true })
  status: string

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

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

  @DeleteDateColumn({ type: "timestamp", nullable: true })
  deleted_at: Date

  @ManyToOne(() => Customer, (customer) => customer.episodes)
  @JoinColumn({ name: "customer_id" })
  customer: Customer

  @OneToMany(() => EpisodeLog, (log) => log.episode)
  logs: EpisodeLog[]

  @OneToMany(() => TripLog, (trip_logs) => trip_logs.episode)
  trip_logs: TripLog[]
}
