-- Migration 15: Fichas, retirada, vouchers e ingressos
-- Source: backend/db/dump/19052026_nextbar.sql

-- -------------------------------------------------------- 15. Fichas, retirada, vouchers e ingressos
--
-- Estrutura para tabela `fichas_impressas`
--

CREATE TABLE `fichas_impressas` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  sale_id INT NOT NULL,
  sale_item_id INT NOT NULL,
  code_sheet VARCHAR(200) NOT NULL,
  number_via INT(11) NOT NULL,
  second_via INT(11),
  print_device VARCHAR(200),
  print_user VARCHAR(200),
  tenant_id INT NOT NULL,
  event_id INT NOT NULL,
  sector_id INT NOT NULL,
  device_id INT NOT NULL,
  cancelled_by INT(11),
  canceled_motivation VARCHAR(200),
  print_mode_form INT(11) NOT NULL,
  printed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  status TINYINT(1) NOT NULL DEFAULT 1,
  trash TINYINT(1) NOT NULL DEFAULT 0,
  FOREIGN KEY (tenant_id) REFERENCES tenants(id),
  FOREIGN KEY (event_id) REFERENCES eventos(id),
  FOREIGN KEY (sector_id) REFERENCES setores(id),
  FOREIGN KEY (device_id) REFERENCES dispositivos(id),
  FOREIGN KEY (sale_id) REFERENCES vendas(id),
  FOREIGN KEY (sale_item_id) REFERENCES itens_venda(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------
--
-- Estrutura para tabela `resgates_fichas`
--

CREATE TABLE `resgates_fichas` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  code_sheet VARCHAR(200) NOT NULL,
  tenant_id INT NOT NULL,
  event_id INT NOT NULL,
  sector_id INT NOT NULL,
  device_id INT NOT NULL,
  resgate_user VARCHAR(200),
  resgate_device VARCHAR(200),
  resgate_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  rejection_at TIMESTAMP NULL,
  rejection_motivation VARCHAR(200),
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  status TINYINT(1) NOT NULL DEFAULT 1,
  trash TINYINT(1) NOT NULL DEFAULT 0,
  FOREIGN KEY (tenant_id) REFERENCES tenants(id),
  FOREIGN KEY (event_id) REFERENCES eventos(id),
  FOREIGN KEY (sector_id) REFERENCES setores(id),  
  FOREIGN KEY (device_id) REFERENCES dispositivos(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
