import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  CreateDateColumn,
} from "typeorm"
import { Project } from "./project.entity"
import { Auth } from "../../auth/entities/auth.entity"

@Entity("project_completion_logs")
export class ProjectCompletionLog {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

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

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

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

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