CREATE TABLE IF NOT EXISTS `swag_enterprise_price_list` (
    `id`       INTEGER(11)  NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `name`     VARCHAR(500) NOT NULL,
    `priority` INTEGER(11)           DEFAULT 0
)
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `swag_enterprise_price_list_condition` (
    `id`            INTEGER(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `price_list_id` INTEGER(11) NOT NULL,
    `type`          VARCHAR(500),
    `value`         VARCHAR(500),
    FOREIGN KEY (price_list_id) REFERENCES swag_enterprise_price_list (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
)
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `swag_enterprise_price_list_prices` (
    `id`            INTEGER(11)  NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `price_list_id` INTEGER(11)  NOT NULL,
    `ordernumber`   VARCHAR(255) NOT NULL,
    `price`         DOUBLE,
    `pseudo_price`  DOUBLE,
    `regulation_price` DOUBLE,
    `from`          INT(11),
    `to`            INT(11),
    `valid_from`    DATETIME     NULL,
    `valid_to`      DATETIME     NULL,
    `calculation`   VARCHAR(255) NULL,
    `gross`         TINYINT(1),
    FOREIGN KEY (price_list_id) REFERENCES swag_enterprise_price_list (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE,
    INDEX `swag_enterprise_price_list_prices_1` (`ordernumber`),
    INDEX `swag_enterprise_price_list_prices_from_to` (`from`, `to`),
    INDEX `swag_enterprise_price_list_prices_valid_from_to` (`valid_from`, `valid_to`)
)
    ENGINE = InnoDB
    DEFAULT CHARSET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

CREATE INDEX swag_enterprise_price_list_priority_index ON swag_enterprise_price_list (priority);

