-- Migration v1.5.2: Role-based menu permissions
CREATE TABLE IF NOT EXISTS role_menu_permissions (
    id SERIAL PRIMARY KEY,
    role VARCHAR(20) NOT NULL,
    menu_key VARCHAR(50) NOT NULL,
    visible BOOLEAN NOT NULL DEFAULT TRUE,
    UNIQUE(role, menu_key)
);

-- Default: enable all menus for both roles
INSERT INTO role_menu_permissions (role, menu_key, visible) VALUES
    ('engineer', 'tasks', true),
    ('engineer', 'reports', true),
    ('engineer', 'incidents', true),
    ('engineer', 'questionnaire', true),
    ('engineer', 'passports', true),
    ('engineer', 'customers', true),
    ('engineer', 'objects', true),
    ('engineer', 'sla', true),
    ('engineer', 'tech_access', true),
    ('engineer', 'docs', true),
    ('technician', 'tasks', true),
    ('technician', 'reports', true),
    ('technician', 'incidents', true),
    ('technician', 'checklist', true)
ON CONFLICT (role, menu_key) DO NOTHING;
