-- +goose Up
-- create routes table
CREATE TABLE IF NOT EXISTS b2b_routes (
  id          INT AUTO_INCREMENT PRIMARY KEY,
  name        VARCHAR(255) NOT NULL UNIQUE,
  path        VARCHAR(255) NULL,
  component   VARCHAR(255) NOT NULL COMMENT 'path to component file',
  layout      VARCHAR(50) DEFAULT 'default' COMMENT "'default' | 'empty'",
  meta        JSON DEFAULT '{}',
  is_active   BOOLEAN DEFAULT TRUE,
  sort_order  INT DEFAULT 0,
  parent_id   INT NULL,

  CONSTRAINT fk_parent
    FOREIGN KEY (parent_id)
    REFERENCES b2b_routes(id)
    ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO b2b_routes
  (name, path, component, layout, meta, is_active, sort_order, parent_id)
VALUES
  ('root', '', '', 'default', '{"trans": "route.root"}', 0, 0, 0),
  ('home', '', '@/views/HomeView.vue', 'default', '{"trans": "route.home"}', 1, 0, 0),
  ('login', 'login', '@/views/LoginView.vue', 'empty', '{"guest":true}', 1, 2, NULL),
  ('register', 'register', '@/views/RegisterView.vue', 'empty', '{"guest":true}', 1, 3, NULL),
  ('password-recovery', 'password-recovery', '@/views/PasswordRecoveryView.vue', 'empty', '{"guest":true}', 1, 4, NULL),
  ('reset-password', 'reset-password', '@/views/ResetPasswordView.vue', 'empty', '{"guest":true}', 1, 5, NULL),
  ('verify-email', 'verify-email', '@/views/VerifyEmailView.vue', 'empty', '{"guest":true}', 1, 6, NULL);


CREATE TABLE IF NOT EXISTS b2b_top_menu (
  menu_id INT AUTO_INCREMENT NOT NULL,
  label LONGTEXT NOT NULL DEFAULT '{}',
  parent_id INT NULL DEFAULT NULL,
  params LONGTEXT NOT NULL DEFAULT '{}',
  active TINYINT NOT NULL DEFAULT 1,
  position INT NOT NULL DEFAULT 1,
  PRIMARY KEY (menu_id),
  CONSTRAINT FK_b2b_top_menu_parent_id FOREIGN KEY (parent_id) 
      REFERENCES b2b_top_menu (menu_id) 
      ON DELETE RESTRICT ON UPDATE RESTRICT,
  INDEX FK_b2b_top_menu_parent_id_idx (parent_id ASC)
) ENGINE = InnoDB;

INSERT IGNORE INTO `b2b_top_menu` (`menu_id`, `label`, `parent_id`, `params`)
VALUES
  -- ROOT
  (
    1,
    '{
  "name": "root",
  "trans": {
    "pl": "Menu główne",
    "en": "Main Menu",
    "de": "Hauptmenü"
  }
}',
    NULL,
    '{}'
  ),
  -- LEVEL 1
  (
    2,
    '{
  "name": "dashboard",
  "trans": {
    "pl": "Panel",
    "en": "Dashboard",
    "de": "Dashboard"
  }
}',
    1,
    '{}'
  ),
  (
    3,
    '{
  "name": "orders",
  "trans": {
    "pl": "Zamówienia",
    "en": "Orders",
    "de": "Bestellungen"
  }
}',
    1,
    '{}'
  ),
  (
    4,
    '{
  "name": "customers",
  "trans": {
    "pl": "Klienci",
    "en": "Customers",
    "de": "Kunden"
  }
}',
    1,
    '{}'
  ),
  (
    5,
    '{
  "name": "products",
  "trans": {
    "pl": "Produkty",
    "en": "Products",
    "de": "Produkte"
  }
}',
    1,
    '{}'
  ),
  (
    6,
    '{
  "name": "reports",
  "trans": {
    "pl": "Raporty",
    "en": "Reports",
    "de": "Berichte"
  }
}',
    1,
    '{}'
  ),
  -- LEVEL 2 (Orders)
  (
    7,
    '{
  "name": "order_list",
  "trans": {
    "pl": "Lista zamówień",
    "en": "Order List",
    "de": "Bestellliste"
  }
}',
    3,
    '{}'
  ),
  (
    8,
    '{
  "name": "pending_orders",
  "trans": {
    "pl": "Oczekujące zamówienia",
    "en": "Pending Orders",
    "de": "Ausstehende Bestellungen"
  }
}',
    3,
    '{}'
  ),
  (
    9,
    '{
  "name": "carts",
  "trans": {
    "pl": "Koszyki",
    "en": "Carts",
    "de": "Warenkörbe"
  }
}',
    3,
    '{}'
  ),
  -- LEVEL 2 (Products)
  (
    10,
    '{
  "name": "product_list",
  "trans": {
    "pl": "Lista produktów",
    "en": "Product List",
    "de": "Produktliste"
  }
}',
    5,
    '{}'
  ),
  (
    11,
    '{
  "name": "categories",
  "trans": {
    "pl": "Kategorie",
    "en": "Categories",
    "de": "Kategorien"
  }
}',
    5,
    '{}'
  ),
  (
    12,
    '{
  "name": "inventory",
  "trans": {
    "pl": "Magazyn",
    "en": "Inventory",
    "de": "Lagerbestand"
  }
}',
    5,
    '{}'
  ),
  -- LEVEL 2 (Customers)
  (
    13,
    '{
  "name": "customer_list",
  "trans": {
    "pl": "Lista klientów",
    "en": "Customer List",
    "de": "Kundenliste"
  }
}',
    4,
    '{}'
  ),
  (
    14,
    '{
  "name": "customer_groups",
  "trans": {
    "pl": "Grupy klientów",
    "en": "Customer Groups",
    "de": "Kundengruppen"
  }
}',
    4,
    '{}'
  );
-- +goose Down

DROP TABLE IF EXISTS b2b_routes;

