-- +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',
  meta        JSON DEFAULT '{}',
  active      BOOLEAN DEFAULT TRUE

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO b2b_routes
  (name, path, component, meta, active)
VALUES
  ('root', '', '', '{"trans": "route.root"}', 0),
  ('home', '', '/views/HomeView.vue', '{"trans": "route.home"}', 1),
  ('login', 'login', '/views/LoginView.vue', '{"guest":true}', 1),
  ('register', 'register', '/views/RegisterView.vue', '{"guest":true}', 1),
  ('password-recovery', 'password-recovery', '/views/PasswordRecoveryView.vue', '{"guest":true}', 1),
  ('reset-password', 'reset-password', '/views/ResetPasswordView.vue', '{"guest":true}', 1),
  ('verify-email', 'verify-email', '/views/VerifyEmailView.vue', '{"guest":true}', 1);


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`, `active`, `position`) VALUES
(1, JSON_COMPACT('{"name":"root","trans":{"pl":{"label":"Menu główne"},"en":{"label":"Main Menu"},"de":{"label":"Hauptmenü"}}}'),NULL,JSON_COMPACT('{}'),1,1),
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);



-- +goose Down

DROP TABLE IF EXISTS b2b_routes;
DROP TABLE IF EXISTS b2b_top_menu;
DROP FUNCTION IF EXISTS `slugify_eu`;
