/**
 * TableroDespacho Entity
 * ERP Transportistas
 *
 * Dispatch board configuration for map and assignment views.
 * Module: MAI-005 Despacho
 * Adapted from: erp-mecanicas-diesel MMD-011 Dispatch Center
 */

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

@Entity({ name: 'tableros_despacho', schema: 'despacho' })
@Index('idx_tableros_despacho_tenant', ['tenantId'])
export class TableroDespacho {
  @PrimaryGeneratedColumn('uuid')
  id: string;

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

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

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

  // Map defaults
  @Column({ name: 'default_zoom', type: 'integer', default: 12 })
  defaultZoom: number;

  @Column({ name: 'centro_lat', type: 'decimal', precision: 10, scale: 7, default: 19.4326 })
  centroLat: number;

  @Column({ name: 'centro_lng', type: 'decimal', precision: 10, scale: 7, default: -99.1332 })
  centroLng: number;

  // Behavior
  @Column({ name: 'intervalo_refresco_segundos', type: 'integer', default: 30 })
  intervaloRefrescoSegundos: number;

  @Column({ name: 'mostrar_unidades_offline', type: 'boolean', default: true })
  mostrarUnidadesOffline: boolean;

  @Column({ name: 'auto_asignar_habilitado', type: 'boolean', default: false })
  autoAsignarHabilitado: boolean;

  @Column({ name: 'max_sugerencias', type: 'integer', default: 5 })
  maxSugerencias: number;

  // Filters
  @Column({ name: 'filtros_default', type: 'jsonb', default: {} })
  filtrosDefault: Record<string, any>;

  @Column({ type: 'boolean', default: true })
  activo: boolean;

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

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

  @Column({ name: 'created_by', type: 'uuid', nullable: true })
  createdBy?: string;
}
