-- gsc-shell-api — seed for the gsc-crm app.
-- Idempotent via ON CONFLICT.

INSERT INTO shell.apps (app_key, display_name, base_url) VALUES
  ('gsc-crm', 'GSC CRM', 'https://crm.gosec.internal')
ON CONFLICT (app_key) DO UPDATE
  SET display_name = EXCLUDED.display_name,
      base_url     = EXCLUDED.base_url;

INSERT INTO shell.branding (app_key, logo_url, product_name, footer_html, brand_color) VALUES
  (
    'gsc-crm',
    'https://assets.gosec.cloud/logos/logo.svg',
    'CRM',
    '© GoSec Cloud',
    NULL
  )
ON CONFLICT (app_key) DO UPDATE
  SET logo_url     = EXCLUDED.logo_url,
      product_name = EXCLUDED.product_name,
      footer_html  = EXCLUDED.footer_html,
      brand_color  = EXCLUDED.brand_color;

-- Sidebar items.
INSERT INTO shell.menu_items (app_key, zone, key, translation_key, href, icon, sort_order) VALUES
  ('gsc-crm', 'sidebar', 'dashboard',     'menu.dashboard',     '/dashboard',     'ph-house',           10),
  ('gsc-crm', 'sidebar', 'accounts',      'menu.accounts',      '/accounts',      'ph-buildings',       20),
  ('gsc-crm', 'sidebar', 'contacts',      'menu.contacts',      '/contacts',      'ph-users',           30),
  ('gsc-crm', 'sidebar', 'leads',         'menu.leads',         '/leads',         'ph-target',          40),
  ('gsc-crm', 'sidebar', 'opportunities', 'menu.opportunities', '/opportunities', 'ph-currency-dollar', 50),
  ('gsc-crm', 'sidebar', 'pipelines',     'menu.pipelines',     '/pipelines',     'ph-kanban',          60),
  ('gsc-crm', 'sidebar', 'activities',    'menu.activities',    '/activities',    'ph-list-checks',     70),
  ('gsc-crm', 'sidebar', 'reports',       'menu.reports',       '/reports',       'ph-chart-bar',       80)
ON CONFLICT (app_key, zone, key) DO UPDATE
  SET translation_key = EXCLUDED.translation_key,
      href            = EXCLUDED.href,
      icon            = EXCLUDED.icon,
      sort_order      = EXCLUDED.sort_order,
      is_active       = true;

-- Top bar (just the user-facing search hint for now).
INSERT INTO shell.menu_items (app_key, zone, key, translation_key, href, icon, sort_order) VALUES
  ('gsc-crm', 'topbar', 'search', 'menu.search', '/search', 'ph-magnifying-glass', 10)
ON CONFLICT (app_key, zone, key) DO UPDATE
  SET translation_key = EXCLUDED.translation_key,
      href            = EXCLUDED.href,
      icon            = EXCLUDED.icon,
      sort_order      = EXCLUDED.sort_order,
      is_active       = true;

-- User menu (top-right dropdown). Sign-out + settings + support.
INSERT INTO shell.menu_items (app_key, zone, key, translation_key, href, icon, sort_order, is_external) VALUES
  ('gsc-crm', 'user-menu', 'settings', 'menu.settings', '/settings',                    'ph-gear',    10, false),
  ('gsc-crm', 'user-menu', 'support',  'menu.support',  'https://support.gosec.cloud/', 'ph-headset', 20, true),
  ('gsc-crm', 'user-menu', 'logout',   'menu.logout',   '/api/auth/signout',            'ph-sign-out',30, false)
ON CONFLICT (app_key, zone, key) DO UPDATE
  SET translation_key = EXCLUDED.translation_key,
      href            = EXCLUDED.href,
      icon            = EXCLUDED.icon,
      sort_order      = EXCLUDED.sort_order,
      is_external     = EXCLUDED.is_external,
      is_active       = true;

-- Footer items.
INSERT INTO shell.menu_items (app_key, zone, key, translation_key, href, icon, sort_order, is_external) VALUES
  ('gsc-crm', 'footer', 'docs', 'footer.docs', 'https://docs.gosec.cloud/', NULL, 10, true)
ON CONFLICT (app_key, zone, key) DO UPDATE
  SET translation_key = EXCLUDED.translation_key,
      href            = EXCLUDED.href,
      sort_order      = EXCLUDED.sort_order,
      is_external     = EXCLUDED.is_external,
      is_active       = true;
