import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Company } from "../../company/entities/company.entity"
import { PartyType } from "../../party-types/entities/party-type.entity"
import { Project } from "../../projects/entities/project.entity"

@Entity("contractors")
export class Contractor extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ type: "varchar", length: 255, nullable: false })
  contractor_name: string

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

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

  @Column({ type: "varchar", length: 255, nullable: true })
  phone_number: string

  @Column({ type: "varchar", length: 255, nullable: true })
  email: string

  @Column({ type: "int", nullable: true })
  project_id: number

  @Column({ type: "text", nullable: true })
  notes: string

  @ManyToOne(() => Company)
  @JoinColumn({ name: "company_id" })
  company: Company

  @ManyToOne(() => PartyType)
  @JoinColumn({ name: "type_id" })
  partyType: PartyType

  @ManyToOne(() => Project)
  @JoinColumn({ name: "project_id" })
  project: Project
}
