import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { Province } from "./Province";
import { SubDistrict } from "./SubDistrict";

@Entity("district")
export class District extends EntityBase {
  @Column({
    nullable: true,
    comment: "เขต",
    length: 255,
    default: null,
  })
  name: string;

  @Column({
    length: 40,
    comment: "คีย์นอก(FK)ของตาราง province",
  })
  provinceId: string;

  // @Column({
  //   comment: "mark",
  //   default: null,
  // })
  // importUpdate: number;

  // @Column({
  //   comment: "refId",
  //   default: null,
  // })
  // refId: number;

  @ManyToOne(() => Province, (province) => province.districts)
  @JoinColumn({ name: "provinceId" })
  province: Province;

  @OneToMany(() => SubDistrict, (subDistrict) => subDistrict.district)
  subDistricts: SubDistrict[];

  @OneToMany(() => District, (district) => district.registrationDistricts)
  registrationDistricts: District[];

  @OneToMany(() => District, (district) => district.currentDistricts)
  currentDistricts: District[];
}

export class CreateDistrict {
  @Column()
  name: string;

  @Column()
  provinceId: string;
}

export type UpdateDistrict = Partial<CreateDistrict>;
