-- Controle do botão "Espelho de Ponto" no app + trilha de aceite legal

ALTER TABLE tenants
  ADD COLUMN app_espelho_ponto_enabled TINYINT(1) NOT NULL DEFAULT 1 AFTER app_solicitacoes_enabled;

CREATE TABLE IF NOT EXISTS tenant_app_espelho_ponto_acceptance_logs (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  tenant_id BIGINT UNSIGNED NOT NULL,
  tenant_user_id BIGINT UNSIGNED NOT NULL,
  accepted_action VARCHAR(32) NOT NULL DEFAULT 'disable',
  legal_reference VARCHAR(120) NOT NULL DEFAULT 'Portaria nº 373/2011',
  ack_portaria_373 TINYINT(1) NOT NULL DEFAULT 0,
  ack_irregular_use_risk TINYINT(1) NOT NULL DEFAULT 0,
  ack_responsibility TINYINT(1) NOT NULL DEFAULT 0,
  reason TEXT NULL,
  geo_lat DECIMAL(10,7) NULL,
  geo_lng DECIMAL(10,7) NULL,
  geo_accuracy_m DECIMAL(10,2) NULL,
  geo_captured_at DATETIME NULL,
  ip_address VARCHAR(64) NULL,
  user_agent VARCHAR(255) NULL,
  accepted_by_name VARCHAR(150) NULL,
  accepted_by_email VARCHAR(190) NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_espelho_accept_tenant_created (tenant_id, created_at),
  KEY idx_espelho_accept_user_created (tenant_user_id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
