/**
 * Supplier Entity
 * Mecánicas Diesel - ERP Suite
 *
 * Represents parts suppliers.
 */

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

@Entity({ name: 'suppliers', schema: 'parts_management' })
@Index('idx_suppliers_tenant', ['tenantId'])
@Index('idx_suppliers_name', ['name'])
export class Supplier {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

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

  @Column({ name: 'legal_name', type: 'varchar', length: 300, nullable: true })
  legalName?: string;

  @Column({ type: 'varchar', length: 13, nullable: true })
  rfc?: string;

  // Contact
  @Column({ name: 'contact_name', type: 'varchar', length: 200, nullable: true })
  contactName?: string;

  @Column({ type: 'varchar', length: 200, nullable: true })
  email?: string;

  @Column({ type: 'varchar', length: 20, nullable: true })
  phone?: string;

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

  // Terms
  @Column({ name: 'credit_days', type: 'integer', default: 0 })
  creditDays: number;

  @Column({ name: 'discount_pct', type: 'decimal', precision: 5, scale: 2, default: 0 })
  discountPct: number;

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

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

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

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

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
