import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Company } from "../../company/entities/company.entity"
import { Client } from "../../clients/entities/client.entity"
import { Auth } from "src/modules/auth/entities/auth.entity"
import { Employee } from "../../employees/entities/employee.entity"

@Entity("projects")
export class Project extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

  @Column({ type: "decimal", precision: 12, scale: 2, nullable: false })
  budget: number

  @Column({ type: "decimal", precision: 12, scale: 2, nullable: false })
  remaining_budget: number

  @Column({ type: "decimal", precision: 12, scale: 2, nullable: true })
  threshold_percentage: number

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

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

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

  @Column({
    type: "smallint",
    default: 0,
  })
  is_threshold_mail_sent: number

  @Column({
    type: "smallint",
    default: 0,
  })
  is_over_budget_mail_sent: number

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

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

  @Column({ type: "decimal", precision: 5, scale: 2, nullable: true })
  completion_percentage: number

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

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

  @ManyToOne(() => Client)
  @JoinColumn({ name: "client_id" })
  client: Client

  @ManyToOne(() => Auth)
  @JoinColumn({ name: "created_by" })
  user: Auth

  @ManyToOne(() => Employee)
  @JoinColumn({ name: "managed_by" })
  project_manager: Employee
}
