/**
 * RateQuote ORM Entity (Infrastructure Layer)
 *
 * TypeORM entity for rate quote persistence
 */

import {
  Entity,
  Column,
  PrimaryColumn,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { CarrierOrmEntity } from './carrier.orm-entity';

@Entity('rate_quotes')
@Index('idx_rate_quotes_carrier', ['carrierId'])
@Index('idx_rate_quotes_origin_dest', ['originCode', 'destinationCode'])
@Index('idx_rate_quotes_container_type', ['containerType'])
@Index('idx_rate_quotes_etd', ['etd'])
@Index('idx_rate_quotes_valid_until', ['validUntil'])
@Index('idx_rate_quotes_created_at', ['createdAt'])
@Index('idx_rate_quotes_search', ['originCode', 'destinationCode', 'containerType', 'etd'])
export class RateQuoteOrmEntity {
  @PrimaryColumn('uuid')
  id: string;

  @Column({ name: 'carrier_id', type: 'uuid' })
  carrierId: string;

  @ManyToOne(() => CarrierOrmEntity, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'carrier_id' })
  carrier: CarrierOrmEntity;

  @Column({ name: 'carrier_name', type: 'varchar', length: 255 })
  carrierName: string;

  @Column({ name: 'carrier_code', type: 'varchar', length: 50 })
  carrierCode: string;

  @Column({ name: 'origin_code', type: 'char', length: 5 })
  originCode: string;

  @Column({ name: 'origin_name', type: 'varchar', length: 255 })
  originName: string;

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

  @Column({ name: 'destination_code', type: 'char', length: 5 })
  destinationCode: string;

  @Column({ name: 'destination_name', type: 'varchar', length: 255 })
  destinationName: string;

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

  @Column({ name: 'base_freight', type: 'decimal', precision: 10, scale: 2 })
  baseFreight: number;

  @Column({ type: 'jsonb', default: '[]' })
  surcharges: any[];

  @Column({ name: 'total_amount', type: 'decimal', precision: 10, scale: 2 })
  totalAmount: number;

  @Column({ type: 'char', length: 3 })
  currency: string;

  @Column({ name: 'container_type', type: 'varchar', length: 20 })
  containerType: string;

  @Column({ type: 'varchar', length: 10 })
  mode: string;

  @Column({ type: 'timestamp' })
  etd: Date;

  @Column({ type: 'timestamp' })
  eta: Date;

  @Column({ name: 'transit_days', type: 'integer' })
  transitDays: number;

  @Column({ type: 'jsonb' })
  route: any[];

  @Column({ type: 'integer' })
  availability: number;

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

  @Column({ name: 'vessel_type', type: 'varchar', length: 100, nullable: true })
  vesselType: string | null;

  @Column({ name: 'co2_emissions_kg', type: 'integer', nullable: true })
  co2EmissionsKg: number | null;

  @Column({ name: 'valid_until', type: 'timestamp' })
  validUntil: Date;

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

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