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

@Entity({ name: 'parts', schema: 'freight' })
@Index(['category'])
export class Part extends BaseEntity {
  @Column({ name: 'name', type: 'varchar' })
  name!: string;

  @Column({ name: 'sku', type: 'varchar', nullable: true })
  sku?: string;

  @Column({ name: 'category', type: 'varchar', nullable: true })
  category?: string; // includes 'TIRE' — doubles as tire inventory

  @Column({ name: 'quantity_in_stock', type: 'int', default: 0 })
  quantityInStock!: number;

  @Column({ name: 'reorder_level', type: 'int', default: 0 })
  reorderLevel!: number;

  @Column({ name: 'unit_cost', type: 'numeric', precision: 14, scale: 2, nullable: true })
  unitCost?: number;

  @Column({ name: 'location', type: 'varchar', nullable: true })
  location?: string;
}
