-- Migration 33: Auditoria global e motivos padronizados
-- Source: backend/db/dump/19052026_nextbar.sql

-- -------------------------------------------------------- 33. Auditoria global e motivos padronizados
--
-- Estrutura para tabela `audit_logs`
--

CREATE TABLE `audit_logs` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  tenant_id INT NOT NULL,
  actor_user_id INT NULL,
  actor_type VARCHAR(100) NOT NULL,
  entity_type VARCHAR(100) NOT NULL,
  entity_id INT NOT NULL,
  action VARCHAR(100) NOT NULL,
  before_json JSON NULL,
  after_json JSON NULL,
  reason TEXT NULL,
  ip_address VARCHAR(100) NULL,
  device_id INT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT 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 (actor_user_id) REFERENCES usuarios(id),
  FOREIGN KEY (device_id) REFERENCES dispositivos(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------
--
-- Estrutura para tabela `motivos_padronizados`
--

CREATE TABLE `motivos_padronizados` (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  tenant_id INT NULL,
  reason_type VARCHAR(100) NOT NULL,
  code VARCHAR(100) NOT NULL,
  description TEXT NOT NULL,
  requires_comment TINYINT(1) NOT NULL DEFAULT 0,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  status TINYINT(1) NOT NULL DEFAULT 1,
  trash TINYINT(1) NOT NULL DEFAULT 0,
  FOREIGN KEY (tenant_id) REFERENCES tenants(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
