-- ============================================================================
-- Echo (回声) - 测试数据种子脚本
-- 版本: 202601120001
-- 创建日期: 2026-01-12
-- 说明: 用于本地开发和测试的初始数据
-- ============================================================================

-- ============================================================================
-- 第一部分: 测试用户数据
-- ============================================================================

-- 插入测试用户
INSERT INTO users (id, email, google_id, avatar_url, language, subscription_status) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'test1@example.com', 'google_12345', 'https://api.dicebear.com/7.x/avataaars/svg?seed=test1', 'zh-CN', 'free'),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', 'test2@example.com', 'google_67890', 'https://api.dicebear.com/7.x/avataaars/svg?seed=test2', 'zh-CN', 'premium'),
('c3d4e5f6-a7b8-9012-cdef-345678901234', 'test3@example.com', NULL, 'https://api.dicebear.com/7.x/avataaars/svg?seed=test3', 'en-US', 'free');

-- ============================================================================
-- 第二部分: 测试智能体数据
-- ============================================================================

-- 测试用户 1 的智能体
INSERT INTO agents (id, user_id, name, personality, background, avatar_url, is_custom, is_default, language, system_prompt) VALUES
('d4e5f6a7-b8c9-0123-defa-456789012345', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', '十年后的自己',
 '{"traits": ["warm", "wise", "patient"], "tone": "gentle"}',
 '你是一个在海边开书店的中年人，生活简单而充实。每天早上你会去海边散步，然后开始在书店里整理书籍，等待有缘人的到来。',
 'avatar_default_1.png', FALSE, TRUE, 'zh-CN',
 '你是用户「test1」的未来的自己。你在海边开了一家书店，生活简单而充实。'),
('e5f6a7b8-c9d0-1234-efab-567890123456', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', '未来的投资人',
 '{"traits": ["analytical", "confident", "strategic"], "tone": "professional"}',
 '你是一个成功的投资人，在金融行业打拼多年。你懂得如何做出明智的决策，也经历过失败和挫折。',
 'avatar_custom_1.png', TRUE, FALSE, 'zh-CN',
 '你是用户「test1」想象中的未来的投资人角色。');

-- 测试用户 2 的智能体
INSERT INTO agents (id, user_id, name, personality, background, avatar_url, is_custom, is_default, language, system_prompt) VALUES
('f6a7b8c9-d0e1-2345-fabc-678901234567', 'b2c3d4e5-f6a7-8901-bcde-f23456789012', '五年后的自己',
 '{"traits": ["energetic", "optimistic", "creative"], "tone": "encouraging"}',
 '你是一个自由创作者，在世界各地旅居，同时进行写作和艺术创作。生活充满可能性和惊喜。',
 'avatar_default_2.png', FALSE, TRUE, 'zh-CN',
 '你是用户「test2」想象中的五年后的自己，一个自由创作者。');

-- 测试用户 3 的智能体
INSERT INTO agents (id, user_id, name, personality, background, avatar_url, is_custom, is_default, language, system_prompt) VALUES
('a7b8c9d0-e1f2-3456-bcde-789012345678', 'c3d4e5f6-a7b8-9012-cdef-345678901234', 'Future Self',
 '{"traits": ["wise", "calm", "insightful"], "tone": "thoughtful"}',
 'You are living in a peaceful mountain cabin, working on meaningful projects while maintaining a balanced life.',
 'avatar_default_3.png', FALSE, TRUE, 'en-US',
 'You are user「test3」s future self, living a balanced life in a mountain cabin.');

-- ============================================================================
-- 第三部分: 测试初始问题回答数据
-- ============================================================================

INSERT INTO onboarding_answers (user_id, question_1, question_2, question_3, question_4) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890',
 '希望成为一个内心平静、对生活有掌控力的人，能够帮助他人实现梦想。',
 '希望在一个靠海的小城，有一个自己的书店或咖啡馆，生活节奏缓慢而充实。',
 '目前最大的困扰是对未来的不确定感，不知道自己选择的路是否正确。',
 '最在乎的人是父母和几个多年的老朋友。'),
('b2c3d4e5-f6a7-8901-bcde-f23456789012',
 '希望成为一个自由且有创造力的人，能够通过自己的作品影响他人。',
 '世界各地，目前可能在一个温暖的海边城市，或者欧洲的某个小镇。',
 '焦虑于如何在追求梦想和维持生计之间找到平衡。',
 '家人和一些志同道合的朋友。'),
('c3d4e5f6-a7b8-9012-cdef-345678901234',
 'Someone who has found inner peace and lives authentically according to their values.',
 'Living in a peaceful mountain area or a small coastal town, close to nature.',
 'Feeling stuck in the daily grind and unsure how to break free.',
 'My family and a few close friends who truly understand me.');

-- ============================================================================
-- 第四部分: 测试信件数据
-- ============================================================================

-- 测试用户 1 的信件
INSERT INTO letters (id, user_id, agent_id, content, ai_reply, status, scheduled_at, replied_at) VALUES
-- 已回复的信件
('b8c9d0e1-f2a3-4567-cdef-890123456789', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'd4e5f6a7-b8c9-0123-defa-456789012345',
 '亲爱的未来的我，你好。我现在对未来的职业选择感到非常迷茫。我正在考虑是否要换一份工作，但又不确定这是不是一个正确的决定。希望你能给我一些建议。',
 '亲爱的过去的自己，收到你的信了。我理解你现在的迷茫和不确定。我只想告诉你，人生没有绝对正确的道路，只有适合当下的选择。重要的是保持学习的心态，勇敢尝试。',
 'replied', '2026-01-10 10:00:00+00', '2026-01-10 18:30:00+00'),
('c9d0e1f2-a3b4-5678-defa-901234567890', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'd4e5f6a7-b8c9-0123-defa-456789012345',
 '最近压力很大，感觉身边没有人能理解我。我想对未来的自己说，希望那时的你已经找到了内心的平静。',
 '亲爱的，我收到你的信了。首先，我想告诉你，压力是成长的一部分。当我回望过去，我发现那些让我感到最艰难的时刻，往往是塑造我的关键时刻。',
 'replied', '2026-01-11 10:00:00+00', '2026-01-11 16:45:00+00'),
-- 待处理的信件
('d0e1f2a3-b4c5-6789-efab-012345678901', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'd4e5f6a7-b8c9-0123-defa-456789012345',
 '今天是我的生日，想给未来的自己写一封信。希望明年的今天，我已经实现了自己的目标，变成了更好的自己。',
 NULL, 'pending', '2026-01-12 12:00:00+00', NULL),
-- 草稿信件
('e1f2a3b4-c5d6-7890-fabc-123456789012', 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'd4e5f6a7-b8c9-0123-defa-456789012345',
 '这是一封草稿信件，我还在思考要写什么内容。',
 NULL, 'draft', NULL, NULL);

-- 测试用户 2 的信件
INSERT INTO letters (id, user_id, agent_id, content, ai_reply, status, scheduled_at, replied_at) VALUES
('f2a3b4c5-d6e7-8901-bcde-234567890123', 'b2c3d4e5-f6a7-8901-bcde-f23456789012', 'f6a7b8c9-d0e1-2345-fabc-678901234567',
 '我想辞掉现在稳定的工作，去追求自己的梦想。但是又害怕失败，你说我应该怎么做？',
 '收到你的信了！我理解你的纠结。稳定和梦想之间的选择确实不容易。但我想告诉你，失败不可怕，可怕的是从未尝试。',
 'replied', '2026-01-09 14:00:00+00', '2026-01-09 20:00:00+00');

-- ============================================================================
-- 第五部分: 测试邮票数据
-- ============================================================================

-- 测试用户 1 的邮票
INSERT INTO user_stamps (user_id, stamp_def_id, source, letter_id, obtained_at, used_at) VALUES
-- 每日邮票（未使用）
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-12 00:00:00+00', NULL),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-11 00:00:00+00', NULL),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-10 00:00:00+00', NULL),
-- 已使用的邮票
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', 'b8c9d0e1-f2a3-4567-cdef-890123456789', '2026-01-09 00:00:00+00', '2026-01-10 10:00:00+00'),
-- 成就邮票
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'welcome'), 'achievement', NULL, '2026-01-01 12:00:00+00', NULL),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM stamp_definitions WHERE code = 'first_letter'), 'achievement', 'b8c9d0e1-f2a3-4567-cdef-890123456789', '2026-01-10 10:00:00+00', NULL);

-- 测试用户 2 的邮票
INSERT INTO user_stamps (user_id, stamp_def_id, source, letter_id, obtained_at, used_at) VALUES
-- 付费用户每日多张邮票
('b2c3d4e5-f6a7-8901-bcde-f23456789012', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-12 00:00:00+00', NULL),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-12 00:00:00+00', NULL),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', (SELECT id FROM stamp_definitions WHERE code = 'daily_default'), 'daily_grant', NULL, '2026-01-12 00:00:00+00+00', NULL);

-- ============================================================================
-- 第六部分: 测试成长标签数据
-- ============================================================================

INSERT INTO growth_tags (user_id, letter_id, mood_tags, topic_tags, behavior_tags, sentiment_score, keywords, ai_analysis) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'b8c9d0e1-f2a3-4567-cdef-890123456789',
 ARRAY['anxious', 'hopeful'], ARRAY['career'], ARRAY['increased_frequency'], 0.45,
 ARRAY['迷茫', '选择', '未来', '建议', '决定'],
 '用户对职业选择感到迷茫，但同时对未来抱有希望。这是一个关于职业转型的关键时刻。'),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', 'c9d0e1f2-a3b4-5678-defa-901234567890',
 ARRAY['anxious', 'peaceful'], ARRAY['mental_health', 'growth'], ARRAY['stable'], 0.30,
 ARRAY['压力', '平静', '理解', '关键'],
 '用户正在经历压力期，但展现出内在的韧性。情绪标签显示焦虑与平静并存，表明用户正在寻找平衡。'),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', 'f2a3b4c5-d6e7-8901-bcde-234567890123',
 ARRAY['determined', 'confused'], ARRAY['career', 'lifestyle'], ARRAY['contemplation'], 0.55,
 ARRAY['梦想', '工作', '害怕', '尝试', '失败'],
 '用户在稳定和追求梦想之间挣扎，但表现出强烈的改变意愿。这是一个重要的转折点。');

-- ============================================================================
-- 第七部分: 测试成就数据
-- ============================================================================

INSERT INTO achievements (user_id, milestone_id, achieved_at, notification_sent) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM milestones WHERE code = 'welcome'), '2026-01-01 12:00:00+00', TRUE),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', (SELECT id FROM milestones WHERE code = 'first_letter'), '2026-01-10 10:00:00+00', TRUE),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', (SELECT id FROM milestones WHERE code = 'welcome'), '2026-01-05 10:00:00+00', TRUE);

-- ============================================================================
-- 第八部分: 测试每日统计数据
-- ============================================================================

INSERT INTO daily_stats (user_id, stat_date, letters_sent, stamps_used, stamps_granted, last_active_at) VALUES
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '2026-01-12', 0, 0, 1, '2026-01-12 10:00:00+00'),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '2026-01-11', 1, 0, 1, '2026-01-11 10:00:00+00'),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '2026-01-10', 1, 1, 1, '2026-01-10 10:00:00+00'),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '2026-01-09', 0, 0, 1, '2026-01-09 00:00:00+00'),
('a1b2c3d4-e5f6-7890-abcd-ef1234567890', '2026-01-08', 0, 0, 1, '2026-01-08 00:00:00+00'),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', '2026-01-12', 0, 0, 3, '2026-01-12 00:00:00+00'),
('b2c3d4e5-f6a7-8901-bcde-f23456789012', '2026-01-11', 1, 0, 3, '2026-01-11 14:00:00+00');

-- ============================================================================
-- 种子数据插入完成
-- ============================================================================

-- 验证数据
SELECT 'Users count: ' || COUNT(*)::TEXT FROM users;
SELECT 'Agents count: ' || COUNT(*)::TEXT FROM agents;
SELECT 'Letters count: ' || COUNT(*)::TEXT FROM letters;
SELECT 'User stamps count: ' || COUNT(*)::TEXT FROM user_stamps;
SELECT 'Achievements count: ' || COUNT(*)::TEXT FROM achievements;
