import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
} from "typeorm"
import { BaseEntity } from "../../common/entities/base.entity"
import { Company } from "../../company/entities/company.entity"
import { Employee } from "../../employees/entities/employee.entity"
import { Project } from "../../projects/entities/project.entity"
import { ActivityType } from "../../activity-types/entities/activity-type.entity"

@Entity("time_tracking")
export class TimeTracking extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number

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

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

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

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

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

  @Column({ type: "timestamp", nullable: false })
  start_time: Date

  @Column({ type: "timestamp", nullable: true })
  end_time: Date

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

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

  @Column({ type: "decimal", nullable: true })
  latitude: number

  @Column({ type: "decimal", nullable: true })
  longitude: number

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

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

  @ManyToOne(() => Employee)
  @JoinColumn({ name: "employee_id" })
  employee: Employee

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

  @ManyToOne(() => ActivityType)
  @JoinColumn({ name: "activity_type_id" })
  activityType: ActivityType
}
