-- -----------------------------------------------------
-- Table `#__sr_discounts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `#__sr_discounts` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` TEXT NULL,
  `description` TEXT NULL,
  `reservation_asset_id` INT(11) UNSIGNED NULL,
  `applied_to` VARCHAR(255) NULL,
  `type` TINYINT(3) UNSIGNED NULL,
  `valid_from` DATE NULL,
  `valid_to` DATE NULL,
  `lower_limit` INT NULL DEFAULT 0,
  `upper_limit` INT NULL DEFAULT 0,
  `value` DECIMAL(12,2) NULL,
  `value_adult` DECIMAL(12,2) NULL,
  `value_child` DECIMAL(12,2) NULL,
  `is_percent` TINYINT(3) NULL DEFAULT 0,
  `state` TINYINT(3) NULL DEFAULT 0,
  `priority` INT(11) UNSIGNED NOT NULL DEFAULT 0,
  `stop_further_processing` TINYINT(3) UNSIGNED NOT NULL DEFAULT 1,
  `scope` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  `applied_days` VARCHAR(45) NULL,
  `applied_type` TINYINT(1) NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sr_discounts_sr_reservation_assets1_idx` (`reservation_asset_id` ASC),
  CONSTRAINT `fk_sr_discounts_sr_reservation_assets1`
  FOREIGN KEY (`reservation_asset_id`)
  REFERENCES `#__sr_reservation_assets` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `#__sr_discount_experience_xref` (
  `discount_id` INT(11) UNSIGNED NOT NULL,
  `experience_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`discount_id`, `experience_id`),
  INDEX `fk_discount_exp_xref_exps1_idx` (`experience_id` ASC),
  CONSTRAINT `fk_discount_exp_xref_discounts1`
    FOREIGN KEY (`discount_id`)
    REFERENCES `#__sr_discounts` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_discount_exp_xref_exps1`
    FOREIGN KEY (`experience_id`)
    REFERENCES `#__sr_experiences` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
