##
##	Carousel structure
##

# module
INSERT INTO `cms__module` (`name`) VALUES ('module.carousel');

SET @moduleID = LAST_INSERT_ID();

# panel
INSERT INTO `cms__panel` (`moduleID`, `name`, `exclusive`, `status`, `parameters`)
VALUES (@moduleID, 'panel.carousel.carousel', 'false', 'active', '{carouselID:null}');
SET @panelCarouselCarouselID = LAST_INSERT_ID();

INSERT INTO `cms__panel` (`moduleID`, `name`, `exclusive`, `status`, `parameters`)
VALUES (@moduleID, 'panel.carousel.admin.carousel', 'true', 'active', NULL);
SET @panelCarouselAdminCarouselID = LAST_INSERT_ID();

INSERT INTO `cms__panel` (`moduleID`, `name`, `exclusive`, `status`, `parameters`)
VALUES (@moduleID, 'panel.carousel.admin.item', 'true', 'active', NULL);
SET @panelCarouselAdminItemID = LAST_INSERT_ID();

# panel variant
INSERT INTO `cms__panel_variant` (`panelID`, `name`, `parameters`, `type`, `status`)
VALUES (@panelVariantCarouselCarouselID, 'CAROUSEL', NULL, 'local', 'active');
INSERT INTO `cms__panel_variant` (`panelID`, `name`, `parameters`, `type`, `status`)
VALUES (@panelVariantCarouselAdminItemID, 'CAROUSEL ADMIN', NULL, 'local', 'active');
INSERT INTO `cms__panel_variant` (`panelID`, `name`, `parameters`, `type`, `status`)
VALUES (@panelVariantCarouselAdminItemID, 'CAROUSEL ITEM ADMIN', NULL, 'local', 'active');

# column_has_panels
INSERT INTO `cms__column_has_panels` (`columnID`, `panelID`, `maxPerColumn`) VALUES (17, @panelCarouselAdminItemID, 1);
INSERT INTO `cms__column_has_panels` (`columnID`, `panelID`, `maxPerColumn`)
VALUES (17, @panelCarouselAdminCarouselID, 1);

# role
INSERT INTO `cms__role` (`roleID`, `moduleID`, `name`, `description`) VALUES ('carousel.user', @moduleID, '', '');
INSERT INTO `cms__role` (`roleID`, `moduleID`, `name`, `description`) VALUES ('carousel.admin', @moduleID, '', '');
INSERT INTO `cms__role` (`roleID`, `moduleID`, `name`, `description`) VALUES ('carousel.guest', @moduleID, '', '');

#resource
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.create', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.createAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.index', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.indexAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.modify', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.modifyAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.delete', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.deleteAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.carousel.index', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.carousel.indexAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.activate', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.activateAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.deactivate', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.deactivateAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.manage', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.carousel.manageAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.index', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.indexAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.create', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.createAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.modify', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.modifyAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.delete', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.deleteAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.activate', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.activateAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.deactivateAction', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.deactivate', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.order', @moduleID, NULL, NULL);
INSERT INTO `cms__resource` (`resourceID`, `moduleID`, `name`, `description`)
VALUES ('carousel.admin.item.orderAction', @moduleID, NULL, NULL);

# role_has_resource
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.index');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.indexAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.modify');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.modifyAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.delete');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.deleteAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.create');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.createAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.carousel.index');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.carousel.indexAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.user', 'carousel.carousel.index');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.user', 'carousel.carousel.indexAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.guest', 'carousel.carousel.index');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.guest', 'carousel.carousel.indexAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.activate');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.activateAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.deactivate');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.deactivateAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.manage');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.carousel.manageAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.admin.item.index');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.indexAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.admin.item.modify');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.modifyAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.admin.item.create');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.createAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.admin.item.delete');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.deleteAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.activate');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.activateAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.deactivateAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.deactivate');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`)
VALUES ('carousel.admin', 'carousel.admin.item.orderAction');
INSERT INTO `cms__role_has_resources` (`roleID`, `resourceID`) VALUES ('carousel.admin', 'carousel.admin.item.order');

# group_has_roles
INSERT INTO `cms__group_has_roles` (`groupID`, `roleID`) VALUES (1, 'carousel.admin');
INSERT INTO `cms__group_has_roles` (`groupID`, `roleID`) VALUES (2, 'carousel.user');
INSERT INTO `cms__group_has_roles` (`groupID`, `roleID`) VALUES (3, 'carousel.guest');

# file
INSERT INTO `cms__file` (`folderID`, `name`, `alias`, `url`, `className`, `status`, `activeFrom`, `activeTo`, `type`, `createDate`, `modifyDate`, `position`)
VALUES
  (7, 'carousel.admin', 'admin.carousel', '/admin/carousel', NULL, 'active', NULL, NULL, 'page', '2017-07-20 14:32:49',
      '2017-07-20 14:32:49', 0);
SET @fileCarouselAdmin = LAST_INSERT_ID();

INSERT INTO `cms__file` (`folderID`, `name`, `alias`, `url`, `className`, `status`, `activeFrom`, `activeTo`, `type`, `createDate`, `modifyDate`, `position`)
VALUES (7, 'Carousel Elem', 'carousel.item.admin', '/admin/carousel/item', NULL, 'active', NULL, NULL, 'page',
           '2017-07-21 14:21:00', '2017-07-21 14:21:00', 0);
SET @fileCarouselItemAdmin = LAST_INSERT_ID();

# file_page
INSERT INTO `cms__file_page` (`fileID`, `layoutID`, `title`, `keywords`, `description`, `editMode`, `editData`)
VALUES (@fileCarouselAdmin, 2, 'Carousel', 'carousel', 'carousel', 'published', NULL);
INSERT INTO `cms__file_page` (`fileID`, `layoutID`, `title`, `keywords`, `description`, `editMode`, `editData`)
VALUES (@fileCarouselItemAdmin, 2, 'Carousel elem adminisztráció', 'admin', 'admin', 'published', NULL);

# file_page_has_panels
INSERT INTO `cms__file_page_has_panels` (`fileID`, `columnID`, `panelVariantID`, `position`)
VALUES (@fileCarouselAdmin, 17, @panelVariantCarouselAdminCarouselID, 1);
INSERT INTO `cms__file_page_has_panels` (`fileID`, `columnID`, `panelVariantID`, `position`)
VALUES (@fileCarouselAdmin, 82, 144, 1);
INSERT INTO `cms__file_page_has_panels` (`fileID`, `columnID`, `panelVariantID`, `position`)
VALUES (@fileCarouselItemAdmin, 17, @panelVariantCarouselAdminItemID, 1);
INSERT INTO `cms__file_page_has_panels` (`fileID`, `columnID`, `panelVariantID`, `position`)
VALUES (@fileCarouselItemAdmin, 82, 144, 1);

# group_has_files
INSERT INTO `cms__group_has_files` (`groupID`, `fileID`, `permissions`)
VALUES (1, @fileCarouselItemAdmin, 'dispatch,view,edit,publish,move,remove');
INSERT INTO `cms__group_has_files` (`groupID`, `fileID`, `permissions`)
VALUES (1, @fileCarouselAdmin, 'dispatch,view,edit,publish,move,remove');
INSERT INTO `cms__group_has_files` (`groupID`, `fileID`, `permissions`) VALUES (32, @fileCarouselAdmin, 'dispatch');
INSERT INTO `cms__group_has_files` (`groupID`, `fileID`, `permissions`) VALUES (32, @fileCarouselItemAdmin, 'dispatch');

# tables
-- CREATE TABLE "carousel__carousel" ---------------------------
CREATE TABLE `carousel__carousel` (
  `carouselID` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
  `status`     VARCHAR(32)
               CHARACTER SET utf8
               COLLATE utf8_general_ci         NOT NULL,
  `name`       VARCHAR(128)
               CHARACTER SET utf8
               COLLATE utf8_general_ci         NOT NULL,
  `options`    JSON                            NULL,
  CONSTRAINT `unique_carouselID` UNIQUE (`carouselID`)
)
  ENGINE = InnoDB;
-- -------------------------------------------------------------

ALTER TABLE `carousel__carousel`
  ADD PRIMARY KEY (`carouselID`);

-- CREATE TABLE "carousel__item" -------------------------------
CREATE TABLE `carousel__item` (
  `itemID`      INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
  `carouselID`  INT(11) UNSIGNED                NOT NULL,
  `imageFileID` INT(11) UNSIGNED                NULL,
  `title`       VARCHAR(64)
                CHARACTER SET utf8
                COLLATE utf8_general_ci         NULL,
  `lead`        VARCHAR(128)
                CHARACTER SET utf8
                COLLATE utf8_general_ci         NULL,
  `description` TEXT CHARACTER SET utf8
                COLLATE utf8_general_ci         NULL,
  `url`         VARCHAR(255)
                CHARACTER SET utf8
                COLLATE utf8_general_ci         NULL,
  `status`      ENUM ('active', 'inactive')
                CHARACTER SET utf8
                COLLATE utf8_general_ci         NOT NULL,
  `position`    INT(11) UNSIGNED                NOT NULL,
  PRIMARY KEY (`itemID`),
  CONSTRAINT `unique_itemID` UNIQUE (`itemID`)
)
  ENGINE = InnoDB;
CREATE INDEX `index_carouselID`
  ON `carousel__item` (`carouselID`);

CREATE INDEX `index_position`
  ON `carousel__item` (`position`);

CREATE TABLE `carousel__carousel` (
  `carouselID` INT(11) UNSIGNED AUTO_INCREMENT NOT NULL,
  `status`     ENUM ('active', 'inactive')
               CHARACTER SET utf8
               COLLATE utf8_general_ci         NOT NULL,
  `name`       VARCHAR(128)
               CHARACTER SET utf8
               COLLATE utf8_general_ci         NOT NULL,
  `options`    JSON                            NULL,
  PRIMARY KEY (`carouselID`)
    CONSTRAINT `unique_carouselID` UNIQUE ( `carouselID` )
)
  CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  ENGINE = InnoDB
  AUTO_INCREMENT = 1;
-- -------------------------------------------------------------

-- CREATE LINK "carousel__carousel_carousel__item" -------------
ALTER TABLE `carousel__item`
  ADD CONSTRAINT `carousel__carousel_carousel__item` FOREIGN KEY (`carouselID`)
REFERENCES `carousel__carousel` (`carouselID`)
  ON DELETE CASCADE
  ON UPDATE CASCADE;
-- -------------------------------------------------------------

-- CREATE LINK "lnk_cms__file_carousel__item" ------------------
ALTER TABLE `carousel__item`
  ADD CONSTRAINT `cms__file_carousel__item` FOREIGN KEY (`imageFileID`)
REFERENCES `cms__file` (`fileID`)
  ON DELETE SET NULL
  ON UPDATE CASCADE;
-- -------------------------------------------------------------

# site
-- CREATE FIELD "carouselFolderID" -----------------------------
ALTER TABLE `cms__site`
  ADD COLUMN `carouselFolderID` INT(11) UNSIGNED NULL;
-- -------------------------------------------------------------

-- CREATE LINK "carousel__carousel_cms__site" ------------------
ALTER TABLE `cms__site`
  ADD CONSTRAINT `carousel__carousel_cms__site` FOREIGN KEY (`carouselFolderID`)
REFERENCES `cms__folder` (`folderID`)
  ON DELETE SET NULL
  ON UPDATE CASCADE;
-- -------------------------------------------------------------

# folder
INSERT INTO `cms__folder` (`folderID`, `parentID`, `name`, `url`, `alias`, `defaultFileID`, `position`, `createDate`, `modifyDate`)
VALUES (915, 7, 'Lapozható elemek mappa', '/admin/carouselfolderid', '', NULL, 2, '2017-07-21 13:23:24',
        '2017-08-08 10:32:04');
SET @carouselFolderID = LAST_INSERT_ID();

INSERT INTO `cms__group_has_folders` (`groupID`, `folderID`, `permissions`)
VALUES (1, @carouselFolderID, 'view,edit,createFile,createFolder,move,remove');
