import {
  Column,
  Entity,
  Index,
  PrimaryColumn,
} from "typeorm";

@Entity("maetie")
export class Tienda {
  @PrimaryColumn({ name: "tienda", type: "int" })
  id: number;

  @Column({ name: "corta", type: "varchar", length: 5, nullable: true })
  @Index()
  codigo: string | null;

  @Column({ name: "descripcion", type: "varchar", length: 255, nullable: true })
  descripcion: string | null;

  @Column({ name: "nombre", type: "varchar", length: 255, nullable: true })
  nombre: string | null;

  @Column({ name: "status", type: "tinyint", nullable: true })
  @Index()
  status: number | null;

  @Column({ name: "alta", type: "char", length: 2, nullable: true })
  alta: string | null;

  @Column({ name: "es_transito", type: "char", length: 1, nullable: true })
  esTransito: string | null;

  @Column({ name: "direccion", type: "varchar", length: 255, nullable: true })
  direccion: string | null;

  @Column({ name: "taller_nombre_impresion", type: "varchar", length: 255, nullable: true })
  nombreImpresion: string | null;

  @Column({ name: "taller_direccion_impresion", type: "varchar", length: 255, nullable: true })
  direccionImpresion: string | null;

  @Column({ name: "taller_telefono_impresion", type: "varchar", length: 80, nullable: true })
  telefonoImpresion: string | null;

  @Column({ name: "taller_logo_url", type: "varchar", length: 500, nullable: true })
  logoUrl: string | null;

  // true cuando mbtaller creo esta fila directo (tenant sin ERP/POSTouch real
  // detras, ej. un demo de ventas) -- false/0 para tiendas que ya venian
  // pobladas por el ERP. Ver AddTiendaCreadaEnTallerFlag1780500000000.
  @Column({ name: "taller_creada_en_taller", type: "tinyint", width: 1, default: 0 })
  creadaEnTaller: boolean;

  // Facturacion automatica a POSTouch, por TIENDA (no por tenant): computadora
  // resuelve a una tienda/caja puntual del lado de POSTouch, asi que cada
  // tienda fisica necesita su propia config -- ver
  // AddTiendaFacturacionPosConfig1780400000000.
  @Column({ name: "taller_facturacion_pos_habilitada", type: "tinyint", width: 1, default: 0 })
  facturacionPosHabilitada: boolean;

  @Column({ name: "taller_facturacion_pos_url", type: "varchar", length: 500, nullable: true })
  facturacionPosUrl: string | null;

  @Column({ name: "taller_facturacion_pos_username", type: "varchar", length: 128, nullable: true })
  facturacionPosUsername: string | null;

  // Cifrado con CredentialsCryptoService, igual que Tenant.dbPasswordEncrypted.
  @Column({ name: "taller_facturacion_pos_password_encrypted", type: "text", nullable: true })
  facturacionPosPasswordEncrypted: string | null;

  @Column({ name: "taller_facturacion_pos_computadora", type: "varchar", length: 64, nullable: true })
  facturacionPosComputadora: string | null;

  // Decimales de redondeo de ESTA tienda POSTouch (ParametrosGlobales.precioDecimales
  // leido manualmente una vez por un administrador — ver spec §11, punto 2).
  @Column({ name: "taller_facturacion_pos_precio_decimales", type: "int", nullable: true })
  facturacionPosPrecioDecimales: number | null;
}
