-- Seed 115 packs for user 144 (iqra.zubiapps@gmail.com)
-- Each pack: 30 stickers, each sticker: 5-10 likes/views/downloads
-- Other user IDs used for engagement: 44-63 (20 users)

SET @uid = 144;

DROP PROCEDURE IF EXISTS seed_user144;

DELIMITER $$

CREATE PROCEDURE seed_user144()
BEGIN
  DECLARE p INT DEFAULT 1;
  DECLARE s INT DEFAULT 1;
  DECLARE pack_id INT;
  DECLARE sticker_id INT;
  DECLARE eng_count INT;
  DECLARE eng_i INT;
  DECLARE other_user INT;

  -- other users pool for engagement
  DECLARE other_users JSON;
  SET other_users = JSON_ARRAY(44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63);

  WHILE p <= 115 DO
    -- create pack
    INSERT INTO pack (user_id, title, is_public, type, status, isDeleted, createdAt, updatedAt)
    VALUES (@uid, CONCAT('Pack ', p), 1, 'regular', 'active', 0, NOW(), NOW());
    SET pack_id = LAST_INSERT_ID();

    SET s = 1;
    WHILE s <= 30 DO
      -- create sticker
      INSERT INTO sticker (pack_id, imageUrl, status, isDeleted, createdAt, updatedAt)
      VALUES (pack_id, CONCAT('https://cdn.stickerly.com/user144/pack', p, '/sticker', s, '.webp'), 1, 0, NOW(), NOW());
      SET sticker_id = LAST_INSERT_ID();

      -- random engagement count 5-10
      SET eng_count = 5 + FLOOR(RAND() * 6);
      SET eng_i = 0;
      WHILE eng_i < eng_count DO
        SET other_user = JSON_EXTRACT(other_users, CONCAT('$[', eng_i MOD 20, ']'));

        -- sticker likes (UNIQUE sticker_id,user_id)
        INSERT IGNORE INTO sticker_likes (sticker_id, user_id, createdAt, updatedAt)
        VALUES (sticker_id, other_user, NOW(), NOW());

        -- sticker views
        INSERT INTO sticker_view (sticker_id, user_id, createdAt, updatedAt)
        VALUES (sticker_id, other_user, NOW(), NOW());

        -- sticker downloads
        INSERT INTO sticker_downloads (sticker_id, user_id, createdAt, updatedAt)
        VALUES (sticker_id, other_user, NOW(), NOW());

        SET eng_i = eng_i + 1;
      END WHILE;

      SET s = s + 1;
    END WHILE;

    SET p = p + 1;
  END WHILE;
END$$

DELIMITER ;

CALL seed_user144();
DROP PROCEDURE IF EXISTS seed_user144;
