﻿import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  JoinColumn,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from "typeorm";
import { TipoVehiculo } from "../../catalogos/entities/tipo-vehiculo.entity";

@Entity("taller_vehiculos")
export class Vehiculo {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 20, unique: true })
  @Index()
  placa: string;

  @Column({ length: 100, nullable: true })
  marca: string;

  @Column({ length: 100, nullable: true })
  modelo: string;

  @Column({ nullable: true })
  anio: number;

  @Column({ length: 100, nullable: true })
  motor: string;

  @Column({ length: 50, nullable: true })
  cilindraje: string;

  @Column({ length: 50, nullable: true })
  color: string;

  @Column({ name: "tipo_vehiculo_id", nullable: true })
  tipoVehiculoId: number;

  @ManyToOne(() => TipoVehiculo)
  @JoinColumn({ name: "tipo_vehiculo_id" })
  tipoVehiculo: TipoVehiculo;

  @Column({ name: "cliente_id", length: 24, nullable: true })
  @Index()
  clienteId: string; // Referencia a maecli.tarjeta

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

  @CreateDateColumn({ name: "created_at" })
  createdAt: Date;

  @UpdateDateColumn({ name: "updated_at" })
  updatedAt: Date;

  @Column({ name: "created_by", nullable: true })
  createdBy: number;

  @Column({ name: "updated_by", nullable: true })
  updatedBy: number;
}
