import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { QueryQuoteEntity } from './query-quote.entity';

@Entity('query_quote_specials')
export class QueryQuoteSpecialEntity extends BaseEntity {
  @ManyToOne(() => QueryQuoteEntity, (q) => q.special_items, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'quote_id' })
  quote: QueryQuoteEntity;

  @Column({ type: 'uuid' })
  quote_id: string;

  @Column({ type: 'varchar', length: 255 })
  service_name: string;

  @Column({ type: 'decimal', precision: 12, scale: 2 })
  total_price: number;

  @Column({ type: 'date', nullable: true })
  date: string | null;

  @Column({ type: 'int', default: 0 })
  sort_order: number;

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

  @Column({ type: 'boolean', default: false })
  is_day_item: boolean;

  // ── Tax snapshot (added 2026-05-07 — see migration 1777700000000) ────
  // See query-quote-hotel.entity.ts for the policy contract.
  @Column({ type: 'jsonb', nullable: true })
  tax_breakdown: Record<string, Record<string, number>> | null;

  @Column({ type: 'decimal', precision: 12, scale: 2, nullable: true })
  tax_amount: number | null;

  /** Per-line slab snapshot (added in migration 1781100000000) — see
   *  query-quote-hotel.entity.ts for the policy. */
  @Column({ type: 'jsonb', nullable: true })
  tax_snapshot: Record<string, unknown> | null;
}
