ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `coupon_id` INT(11) UNSIGNED NULL DEFAULT NULL AFTER `payment_method_discount`,
  ADD INDEX `fk_exp_res_coupons1_idx` (`coupon_id` ASC),
  ADD CONSTRAINT `fk_exp_res_coupons1`
    FOREIGN KEY (`coupon_id`)
    REFERENCES `#__sr_coupons` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION;

ALTER TABLE `#__sr_experience_reservations`
  CHANGE COLUMN `coupon_code` `coupon_code` VARCHAR(255) NULL AFTER `coupon_id`;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `coupon_amount` DECIMAL(12,2) UNSIGNED NOT NULL DEFAULT 0.00 AFTER `coupon_code`;


CREATE TABLE IF NOT EXISTS `#__sr_experience_timeslots` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `experience_id` INT(11) UNSIGNED NOT NULL,
  `guide_id` INT(11) UNSIGNED NOT NULL,
  `from` TIME NOT NULL,
  `to` TIME NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_exp_timeslots_exp1_idx` (`experience_id` ASC),
  CONSTRAINT `fk_exp_timeslots_exps1`
    FOREIGN KEY (`experience_id`)
    REFERENCES `#__sr_experiences` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
)
  ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_experience_guides` (
  `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `state` TINYINT(3) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `partner_id` INT(11) UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `#__sr_experience_guide_user_xref` (
  `guide_id` INT(11) UNSIGNED NOT NULL,
  `user_id` INT(11) UNSIGNED NOT NULL,
  PRIMARY KEY (`guide_id`, `user_id`)
)
  ENGINE = InnoDB;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `time_slot_id` INT(11) UNSIGNED NULL AFTER `coupon_amount`,
  ADD INDEX `fk_exp_res_exp_timeslots_idx` (`time_slot_id` ASC),
  ADD CONSTRAINT `fk_exp_res_exp_timeslots1`
    FOREIGN KEY (`time_slot_id`)
    REFERENCES `#__sr_experience_timeslots` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `guide_id` INT(11) UNSIGNED NULL AFTER `time_slot_id`,
  ADD INDEX `fk_exp_res_exp_guides1_idx` (`guide_id` ASC),
  ADD CONSTRAINT `fk_exp_res_exp_guides1`
    FOREIGN KEY (`guide_id`)
    REFERENCES `#__sr_experience_guides` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `guide_name` VARCHAR(255) NULL DEFAULT NULL AFTER `guide_id`;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `time_slot_from` TIME NULL DEFAULT NULL AFTER `guide_name`;

ALTER TABLE `#__sr_experience_reservations`
  ADD COLUMN `time_slot_to` TIME NULL DEFAULT NULL AFTER `time_slot_from`;
