
UPDATE `wa_price` SET `live` = 0 WHERE `description` LIKE 'Elite %';

UPDATE `was_user_group` SET `membership_level` = 'PREMIUM' WHERE `name` IN ('Premium', 'Premium Limited');

UPDATE `was_user_group` SET `membership_level` = 'PPLUS' WHERE `name` IN ('Admin');

INSERT INTO `was_user_group` (`user_group_id`, `name`, `membership_level`)
VALUES (9, 'Premium Plus', 'PPLUS');

INSERT INTO was_user_group_limit (`user_group_id`, `type`, `limit`)
VALUES
(9, 'EMAIL_ACCOUNTS', 120)
, (9, 'DOMAIN_HOSTING_ANY', 25);


INSERT INTO `wa_price` (`price_id`, `campaign_id`, `description`, `num_months`, `price`, `price_point`, `display_full_name`, `display_short_name`, `live`, `group_id`, `tier`, `free_member_commission`) VALUES
(25, 'b46e6718', 'Premium Plus Monthly Subscription', 1, 99.00, 'monthly', 'Monthly', 'month', 1, 16, 1, 24.00)
, (26, 'd687b7bd', 'Premium Plus Yearly Subscription', 12, 995.00, 'yearly', 'Yearly', 'year', 1, 16, 1, 239.00)
, (27, '8fdf992a', 'Premium Plus Monthly Discount Subscription', 1, 49.00, 'monthly', 'Monthly', 'month', 1, 16, 1, 11.75)
, (28, 'aa9583d8', 'Premium BlackFriday Yearly Subscription', 12, 395.00, 'yearly', 'Yearly', 'year', 1, 15, 1, 95.00)
, (29, 'b0f78c6b', 'Premium Plus BlackFriday Yearly Subscription', 12, 795.00, 'yearly', 'Yearly', 'year', 1, 16, 1, 191.00);


CREATE TABLE `was_upgrade_feature` (
  `upgrade_feature_id` int(11) NOT NULL AUTO_INCREMENT,
  `feature_text` varchar(50) NOT NULL,
  `price_plan` enum('premium','premium_plus') NOT NULL,
  `price_point` enum('any','monthly','yearly') NOT NULL,
  `display_order` int(11) unsigned NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`upgrade_feature_id`),
  KEY `idx_price_plan` (`price_plan`),
  KEY `idx_display_order` (`display_order`)
) ENGINE=InnoDB;

CREATE TRIGGER `was_upgrade_feature_insert_timestamp` BEFORE INSERT ON `was_upgrade_feature` FOR EACH ROW SET NEW.insert_timestamp = NOW();

INSERT INTO `was_upgrade_feature` (`feature_text`, `price_plan`, `price_point`, `display_order`) VALUES
('{{website_count}} Websites', 'premium', 'any', 1)
, ('Jaaxy {{jaaxy_plan}}', 'premium', 'any', 2)
, ('2x Affiliate Commissions', 'premium', 'any', 3)
, ('Premium Website', 'premium', 'any', 4)
, ('Yearly Bonus: {{free_month_count}} Months Free', 'premium', 'yearly', 1)
, ('Yearly Bonus: {{community_credits}} Credits', 'premium', 'yearly', 2)
, ('Yearly Bonus: {{free_domain_count}} Free Domain', 'premium', 'yearly', 3)
, ('Everything in Premium', 'premium_plus', 'any', 1)
, ('{{website_count}} Websites', 'premium_plus', 'any', 2)
, ('Jaaxy {{jaaxy_plan}}', 'premium_plus', 'any', 3)
, ('Expert Classes Plus (multiple weekly)', 'premium_plus', 'any', 4)
, ('All Future Premium Plus Updates', 'premium_plus', 'any', 5)
, ('Yearly Bonus: {{free_month_count}} Months Free', 'premium_plus', 'yearly', 1)
, ('Yearly Bonus: {{community_credits}} Credits', 'premium_plus', 'yearly', 2)
, ('Yearly Bonus: {{free_domain_count}} Free Domains', 'premium_plus', 'yearly', 3);


ALTER TABLE `was_yearly_upgrade_premium_bonus` ADD `price_plan` ENUM('premium', 'premium_plus') NOT NULL DEFAULT 'premium'  AFTER `paypal_id`
, ADD INDEX `idx_price_plan` (`price_plan`);


CREATE TABLE `was_discount_used` (
  `discount_used_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `price_id` int(11) unsigned NOT NULL COMMENT 'Upgraded from price point',
  `paypal_id` int(11) unsigned NOT NULL,
  `price_plan` ENUM('premium', 'premium_plus') NOT NULL DEFAULT 'premium',
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`discount_used_id`),
  KEY `idx_user` (`user_id`),
  KEY `idx_price` (`price_id`),
  KEY `idx_paypal` (`paypal_id`),
  KEY `idx_price_plan` (`price_plan`)
) ENGINE=InnoDB COMMENT='Track users who have used monthly discount';

CREATE TRIGGER `was_discount_used_insert_timestamp` BEFORE INSERT ON `was_discount_used` FOR EACH ROW SET NEW.insert_timestamp = NOW();


CREATE TABLE `was_user_price_history` (
  `user_price_history_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `old_price_id` int(11) unsigned NOT NULL,
  `old_user_group_id` int(11) unsigned NOT NULL,
  `old_plan` enum('premium', 'premium_plus') NOT NULL DEFAULT 'premium',
  `new_price_id` int(11) unsigned NOT NULL,
  `new_user_group_id` int(11) unsigned NOT NULL,
  `new_plan` enum('premium', 'premium_plus') NOT NULL DEFAULT 'premium',
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY  (`user_price_history_id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_old_plan` (`old_plan`),
  KEY `idx_new_plan` (`new_plan`)
) ENGINE=InnoDB COMMENT='Track users price point and user group history';

CREATE TRIGGER `was_user_price_history_insert_timestamp` BEFORE INSERT ON `was_user_price_history` FOR EACH ROW SET NEW.insert_timestamp = NOW();


CREATE TABLE `was_user_downgrade_queue` (
  `user_downgrade_queue_id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `downgrade_timestamp` timestamp NULL DEFAULT NULL,
  `downgrade_plan` enum('premium', 'premium_plus') NOT NULL DEFAULT 'premium',
  `downgrade_price_id` int(11) unsigned NOT NULL,
  `downgrade_user_group_id` int(11) unsigned NOT NULL,
  `downgrade_paid_price` decimal(10,2) NOT NULL DEFAULT '0.00',
  `downgrade_status` enum('QUEUED', 'COMPLETED', 'CANCELLED', 'FAILED') NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_downgrade_queue_id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_downgrade_status_timestamp` (`downgrade_status`, `downgrade_timestamp`)
) ENGINE=InnoDB COMMENT='Track users price point downgrade queue';

CREATE TRIGGER `was_user_downgrade_queue_insert_timestamp` BEFORE INSERT ON `was_user_downgrade_queue` FOR EACH ROW SET NEW.insert_timestamp = NOW();