/**
 * Organization ORM Entity (Infrastructure Layer)
 *
 * TypeORM entity for organization persistence
 */

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

@Entity('organizations')
@Index('idx_organizations_type', ['type'])
@Index('idx_organizations_scac', ['scac'])
@Index('idx_organizations_active', ['isActive'])
export class OrganizationOrmEntity {
  @PrimaryColumn('uuid')
  id: string;

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

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

  @Column({ type: 'char', length: 4, nullable: true, unique: true })
  scac: string | null;

  @Column({ type: 'char', length: 9, nullable: true })
  siren: string | null;

  @Column({ type: 'varchar', length: 17, nullable: true })
  eori: string | null;

  @Column({ name: 'contact_phone', type: 'varchar', length: 50, nullable: true })
  contactPhone: string | null;

  @Column({ name: 'contact_email', type: 'varchar', length: 255, nullable: true })
  contactEmail: string | null;

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

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

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

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

  @Column({ name: 'address_country', type: 'char', length: 2 })
  addressCountry: string;

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

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

  @Column({ type: 'varchar', length: 14, nullable: true })
  siret: string | null;

  @Column({ name: 'siret_verified', type: 'boolean', default: false })
  siretVerified: boolean;

  @Column({ name: 'status_badge', type: 'varchar', length: 20, default: 'none' })
  statusBadge: string;

  @Column({ name: 'is_carrier', type: 'boolean', default: false })
  isCarrier: boolean;

  @Column({ name: 'carrier_type', type: 'varchar', length: 50, nullable: true })
  carrierType: string | null;

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

  @Column({ name: 'default_language', type: 'varchar', length: 2, default: 'fr' })
  defaultLanguage: string;

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

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