/**
 * Engine Catalog Entity
 * Mecánicas Diesel - ERP Suite
 *
 * Global catalog of diesel engine models.
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  Index,
  Check,
} from 'typeorm';

@Entity({ name: 'engine_catalog', schema: 'vehicle_management' })
@Check('chk_horsepower', '"horsepower_max" >= "horsepower_min"')
@Check('chk_years', '"year_end" IS NULL OR "year_end" >= "year_start"')
export class EngineCatalog {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'varchar', length: 50 })
  make: string;

  @Column({ type: 'varchar', length: 50 })
  model: string;

  @Column({ type: 'integer', nullable: true })
  cylinders?: number;

  @Column({ type: 'decimal', precision: 5, scale: 2, nullable: true })
  displacement?: number;

  @Column({ name: 'fuel_type', type: 'varchar', length: 20, default: 'diesel' })
  fuelType: string;

  @Column({ name: 'horsepower_min', type: 'integer', nullable: true })
  horsepowerMin?: number;

  @Column({ name: 'horsepower_max', type: 'integer', nullable: true })
  horsepowerMax?: number;

  @Column({ name: 'torque_max', type: 'integer', nullable: true })
  torqueMax?: number;

  @Column({ name: 'injection_system', type: 'varchar', length: 50, nullable: true })
  injectionSystem?: string;

  @Column({ name: 'year_start', type: 'integer', nullable: true })
  yearStart?: number;

  @Column({ name: 'year_end', type: 'integer', nullable: true })
  yearEnd?: number;

  @Column({ type: 'text', nullable: true })
  notes?: string;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;
}
