CREATE TABLE IF NOT EXISTS `ohrm_theme` (
  `theme_id` bigint(20) not null auto_increment,
  `name` varchar(255) not null,
  `short_name` varchar(255) not null,
  `is_default` boolean not null,
  `colors` varchar(5000) not null,
  `login_button_colors` varchar(255) not null,
  `login_banner` LONGBLOB,
  `client_logo` LONGBLOB,
  `client_logo_small` LONGBLOB,
  `footer_images` varchar(5) NOT NULL ,
  `banner_placement` varchar(6) NOT NULL ,
  `banner_width`  INT(4),
  primary key  (`theme_id`)
) engine=innodb default charset=utf8;

SET @admin_module_id := (SELECT id FROM ohrm_module WHERE name = 'admin');

SET @admin_user_role_id := 1;
SET @ess_user_role_id := 2;
SET @supervisor_user_role_id := 3;
SET @sys_admin_user_role_id := 4;

INSERT INTO `ohrm_config` VALUES ('theme.customer_name', '');

-- Theme Builder Screen
INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`, `route_name`) VALUES
('Theme Builder', @admin_module_id, 'themeBuilder', 'admin_themeBuilder');

SET @theme_builder_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'Theme Builder');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@sys_admin_user_role_id, @theme_builder_screen_id, '1', '1', '1', '1');

INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`, `route_name`) VALUES
('OXD Theme Builder', @admin_module_id, 'oxdThemeBuilder', 'admin_oxdThemeBuilder');

SET @oxd_theme_builder_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'OXD Theme Builder');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@sys_admin_user_role_id, @oxd_theme_builder_screen_id, 1, 1, 1, 1);

SET @admin_menu_item_id := (SELECT id FROM ohrm_menu_item WHERE menu_title = 'Admin');

-- INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
-- ('Themes', @theme_builder_screen_id, @admin_menu_item_id, 2, 1000, '', 1);

SET @people_management_pillar_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'People Management' AND parent_id IS NULL AND level = 1);
SET @hr_administrations_module_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'HR Administration' AND parent_id = @people_management_pillar_menu_id AND level = 2);
SET @configurations_menu_id := (SELECT `id` FROM ohrm_menu_item WHERE `menu_title` = 'Configurations' AND parent_id = @hr_administrations_module_menu_id AND level = 3);

INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
    ('Theme', null, @configurations_menu_id, 4, 800, '', 1);

SET @theme_menu_id := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('Theme Colors', @theme_builder_screen_id, @theme_menu_id, 5, 100, '', 1);

INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
    ('OXD Theme Colors', @oxd_theme_builder_screen_id, @theme_menu_id, 5, 200, '', 1);

-- Image Uploader Screen
INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`, `route_name`) VALUES
('Theme Images', @admin_module_id, 'imageUploader', 'admin_imageUploader');

SET @image_uploader_screen_id := (SELECT id FROM ohrm_screen WHERE name = 'Theme Images');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@sys_admin_user_role_id, @image_uploader_screen_id, '1', '1', '1', '1');

INSERT INTO `ohrm_menu_item` (`menu_title`, `screen_id`, `parent_id`, `level`, `order_hint`, `url_extras`, `status`) VALUES
('Theme Images', @image_uploader_screen_id, @theme_menu_id, 5, 300, '', 1);

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('admin_themes', 'HR Administration - Themes', 1, 1, 1, 1);

SET @theme_data_group_id := (SELECT id FROM ohrm_data_group WHERE name = 'admin_themes');

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`, `data_group_id`, `can_read`, `can_create`, `can_update`, `can_delete`, `self`) VALUES
(@sys_admin_user_role_id, @theme_data_group_id, 1, 1, 1, 1, 0);

INSERT INTO `ohrm_data_group_screen` (`data_group_id`, `screen_id`, `permission`) VALUES
(@theme_data_group_id, @theme_builder_screen_id, 1),
(@theme_data_group_id, @image_uploader_screen_id, 1),
(@theme_data_group_id, @oxd_theme_builder_screen_id, 1);

-- Login Preview Screen
INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`) VALUES
('Login Preview', @admin_module_id, 'loginPreview');

SET @login_preview_screen_id := (SELECT id FROM `ohrm_screen` WHERE name = 'Login Preview');

INSERT INTO `ohrm_user_role_screen` (`user_role_id`, `screen_id`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
(@sys_admin_user_role_id, @login_preview_screen_id, '1', '0', '0', '0');

