import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index } from 'typeorm';

/**
 * A truck configuration EDR registers vehicles against — back-office managed so
 * new configurations arrive without a code change.
 *
 * Two fields drive vehicle registration:
 * - `capacityTons` pre-fills a vehicle's capacity (capacity belongs to the type,
 *   not to each individual truck).
 * - `hasTrailer` decides whether a trailer plate applies at all. A rigid truck
 *   (e.g. Casoni) has none, and registering one with a trailer plate is rejected.
 */
@Entity({ schema: 'freight', name: 'truck_types' })
@Index(['code'])
@Index(['isActive'])
export class TruckType extends BaseEntity {
  /**
   * Matching key, upper-case. Denormalised onto `vehicles.vehicle_type`, which
   * truck-detention billing groups and matches fee rules by — so a code change
   * here is a billing-visible change.
   */
  @Column({ name: 'code', type: 'varchar', length: 32, unique: true })
  code!: string;

  @Column({ name: 'name', type: 'varchar', length: 100 })
  name!: string;

  @Column({ name: 'capacity_tons', type: 'numeric', precision: 10, scale: 3, nullable: true })
  capacityTons?: number | null;

  @Column({ name: 'has_trailer', type: 'boolean', default: false })
  hasTrailer!: boolean;

  @Column({ name: 'description', type: 'text', nullable: true })
  description?: string | null;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive!: boolean;
}
