-- Criar tabela para configurações do sistema
CREATE TABLE IF NOT EXISTS system_config (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    installation_type ENUM('gestor', 'motorista') NOT NULL,
    device_id VARCHAR(100) NOT NULL,
    app_version VARCHAR(20) NOT NULL,
    config_data JSON NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    UNIQUE KEY unique_device (device_id)
);

-- Criar tabela para configurações de usuário
CREATE TABLE IF NOT EXISTS user_config (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    user_id VARCHAR(50) NOT NULL,
    user_type ENUM('gestor', 'motorista') NOT NULL,
    device_id VARCHAR(100) NOT NULL,
    default_screen VARCHAR(50) NOT NULL,
    notification_preferences JSON,
    app_preferences JSON,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    
    UNIQUE KEY unique_user_device (user_id, device_id)
);

-- Inserir configurações padrão
INSERT INTO system_config (installation_type, device_id, app_version, config_data) VALUES
('gestor', 'default_gestor', '1.0.0', '{"user_type":"gestor","default_screen":"gestor_dashboard","show_approval_buttons":true,"can_approve_requests":true,"can_view_reports":true,"notification_types":["solicitacao_viagem","relatorio_diario"],"permissions":{"approve_requests":true,"deny_requests":true,"view_all_requests":true,"manage_drivers":true,"view_reports":true}}'),
('motorista', 'default_motorista', '1.0.0', '{"user_type":"motorista","default_screen":"motorista_dashboard","show_approval_buttons":false,"can_approve_requests":false,"can_view_reports":false,"notification_types":["aprovacao_viagem","negacao_viagem","viagem_iniciada"],"permissions":{"create_requests":true,"start_trips":true,"end_trips":true,"view_own_requests":true,"view_own_trips":true}}'); 