-- Convert existing 500 tickets task to 50 tickets task and add 3 new "Other" type tasks
-- These tasks are displayed in ascending order by requirement (display_order)
-- requirement is in bigint format (tickets * 1,000,000)
-- reward_amount is in bigint format (tickets * 1,000,000)

-- Alter requirement column to BIGINT to support large values for "other" type tasks
-- The column was originally INT, but "other" tasks need BIGINT for deposit_total values
ALTER TABLE `tasks` MODIFY COLUMN `requirement` BIGINT NOT NULL COMMENT 'Number required (e.g., number of friends to invite, or deposit_total in bigint for other tasks)';

-- Convert existing 500 tickets task to 50 tickets task
-- Update requirement from 500000000 (500 tickets) to 50000000 (50 tickets)
-- Update reward from 100000000 (100 tickets) to 5000000 (5 tickets)
-- Update description and display_order
UPDATE `tasks`
SET `requirement` = 50000000,
    `reward_amount` = 5000000,
    `description` = 'Top up Balance: 50 Tickets',
    `display_order` = 1
WHERE `type` = 'other' AND `requirement` = 500000000;

-- Task 2: 250 tickets requirement, 25 tickets reward
INSERT INTO `tasks` (`type`, `requirement`, `reward_amount`, `reward_type`, `display_order`, `title`, `description`) 
SELECT 'other', 250000000, 25000000, 'Stars', 2, 'Top up Balance', 'Top up Balance: 250 Tickets'
WHERE NOT EXISTS (
    SELECT 1 FROM `tasks` WHERE `type` = 'other' AND `requirement` = 250000000
);

-- Task 3: 1000 tickets requirement, 100 tickets reward
INSERT INTO `tasks` (`type`, `requirement`, `reward_amount`, `reward_type`, `display_order`, `title`, `description`) 
SELECT 'other', 1000000000, 100000000, 'Stars', 3, 'Top up Balance', 'Top up Balance: 1000 Tickets'
WHERE NOT EXISTS (
    SELECT 1 FROM `tasks` WHERE `type` = 'other' AND `requirement` = 1000000000
);

-- Task 4: 5000 tickets requirement, 500 tickets reward
INSERT INTO `tasks` (`type`, `requirement`, `reward_amount`, `reward_type`, `display_order`, `title`, `description`) 
SELECT 'other', 5000000000, 500000000, 'Stars', 4, 'Top up Balance', 'Top up Balance: 5000 Tickets'
WHERE NOT EXISTS (
    SELECT 1 FROM `tasks` WHERE `type` = 'other' AND `requirement` = 5000000000
);

