CREATE TABLE IF NOT EXISTS capabilities (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(150) NOT NULL,
  description TEXT,
  parameters TEXT,
  approval_required TINYINT DEFAULT 1,
  category VARCHAR(50) DEFAULT 'fusion',
  risk_level INT DEFAULT 1,
  requires_user_presence TINYINT DEFAULT 0,
  autonomous TINYINT DEFAULT 0,
  cooldown_seconds INT DEFAULT 0,
  handler VARCHAR(150)
);
INSERT INTO capabilities (name, description, approval_required, category, risk_level, handler) VALUES
('fusion.client.list', "List clients (GET /clients)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.client.get', "Get client by id (GET /clients/{id})", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.client.create', "Create client (POST /clients)", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.client.update', "Update client (PUT /clients/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.client.delete', "Delete client (DELETE /clients/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.client.archive', "Archive client (PUT /clients/archive/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.client.projects', "Get client projects (GET /clients/projects/{id})", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.invoice.list', "List invoices (GET /invoices)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.invoice.get', "Get invoice (GET /invoices/{id})", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.invoice.create', "Create invoice (POST /invoices)", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.invoice.update', "Update invoice (PUT /invoices/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.invoice.delete', "Delete invoice (DELETE /invoices/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.product.list', "List products (GET /products)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.product.get', "Get product (GET /products/{id})", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.product.create', "Create product (POST /products)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.product.update', "Update product (PUT /products/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.product.delete', "Delete product (DELETE /products/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.order.list', "List orders (GET /orders)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.order.get', "Get order (GET /orders/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.order.create', "Create order (POST /orders)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.order.update', "Update order (PUT /orders/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.order.delete', "Delete order (DELETE /orders/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.task.list', "List tasks (GET /tasks)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.task.get', "Get task (GET /tasks/{id})", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.task.create', "Create task (POST /tasks)", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.task.update', "Update task (PUT /tasks/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.task.delete', "Delete task (DELETE /tasks/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.task.assign', "Assign task (PUT /tasks/assign/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.lead.list', "List leads (GET /crm/leads)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.lead.get', "Get lead (GET /crm/leads/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.lead.create', "Create lead (POST /crm/leads)", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.lead.update', "Update lead (PUT /crm/leads/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.lead.delete', "Delete lead (DELETE /crm/leads/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.lead.convert', "Convert lead (POST /leads/convert/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.crm.dashboard', "CRM dashboard (GET /crm/dashboard)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.payment.list', "List payments (GET /payments)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.payment.get', "Get payment (GET /payments/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.payment.create', "Create payment (POST /payments)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.payment.update', "Update payment (PUT /payments/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.payment.delete', "Delete payment (DELETE /payments/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.payment.initiate', "Initiate payment (POST /payments/initiate)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.payment.status', "Payment status by quote id (GET /payments/status/{quote_id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.payment.quote', "Get quote by quote id (GET /payments/quote/{quote_id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.payment.provider', "Suggest provider (GET /payments/provider/{quote_id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.subscription.list', "List subscriptions (GET /subscriptions)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.subscription.create', "Create subscription (POST /subscriptions)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.subscription.update', "Update subscription (PUT /subscriptions/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.subscription.delete', "Delete subscription (DELETE /subscriptions/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.contract.get', "Get contract (GET /contracts/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.contract.sign', "Sign contract (POST /contracts/sign)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.contract.status', "Contract status (GET /contracts/status/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.dashboard', "Dashboard (GET /dashboard)", 0, 'fusion', 1, 'FusionModule@handle'),
('fusion.project.list', "List projects (GET /projects)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.project.get', "Get project (GET /projects/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.project.create', "Create project (POST /projects)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.project.update', "Update project (PUT /projects/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.project.delete', "Delete project (DELETE /projects/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.project.status', "Update project status (PUT /projects/status/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.project.comments', "Get project comments (GET /projects/comments/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.project.add_comment', "Add project comment (POST /projects/comments/{id})", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.domain.list', "List domains (GET /domains)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.domain.get', "Get domain (GET /domains/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.domain.create', "Create domain (POST /domains)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.domain.update', "Update domain (PUT /domains/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.domain.delete', "Delete domain (DELETE /domains/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.hosting.list', "List hosting (GET /hosting)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.hosting.get', "Get hosting (GET /hosting/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.hosting.create', "Create hosting (POST /hosting)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.hosting.update', "Update hosting (PUT /hosting/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.hosting.delete', "Delete hosting (DELETE /hosting/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.voip.list', "List VoIP (GET /voip)", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.voip.get', "Get VoIP (GET /voip/{id})", 0, 'fusion', 2, 'FusionModule@handle'),
('fusion.voip.create', "Create VoIP (POST /voip)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.voip.update', "Update VoIP (PUT /voip/{id})", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.voip.delete', "Delete VoIP (DELETE /voip/{id})", 1, 'fusion', 5, 'FusionModule@handle'),
('fusion.duo.domain.register', "DuoServers register domain (POST /duoservers/domain/register)", 1, 'fusion', 4, 'FusionModule@handle'),
('fusion.duo.domain.details', "DuoServers domain details (PUT /duoservers/domain/details)", 1, 'fusion', 3, 'FusionModule@handle'),
('fusion.duo.domain.list', "DuoServers list domains (GET /duoservers/domain/list)", 0, 'fusion', 2, 'FusionModule@handle');
