import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  OneToMany,
  JoinColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
} from "typeorm"
import { Customer } from "src/modules/customers/entities/customer.entity"
import { CustomerTreatmentPlanImage } from "./customer_treatment_images.entity"

@Entity("customer_treatment_plans")
export class CustomerTreatmentPlan {
  @PrimaryGeneratedColumn()
  id: number

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

  @Column({ type: "varchar", nullable: true })
  comments: 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.treatment_plans, {
    onDelete: "CASCADE",
  })
  @JoinColumn({ name: "customer_id" })
  customer: Customer

  @OneToMany(
    () => CustomerTreatmentPlanImage,
    (image) => image.treatment_plan,
    { cascade: true },
  )
  images: CustomerTreatmentPlanImage[]
}
