-- mock_info.sql
-- 生成多语言AI资讯系统主要表的测试数据，每表50条以上



-- 3. ak_content_categories
INSERT INTO public.ak_content_categories (id, name_key, level, ai_keywords, is_active, created_at) VALUES
  (gen_random_uuid(), 'news.politics', 0, ARRAY['政治', '政府', '政策'], true, now()),
  (gen_random_uuid(), 'news.economy', 0, ARRAY['经济', '金融', '股市'], true, now()),
  (gen_random_uuid(), 'news.technology', 0, ARRAY['科技', 'AI', '互联网'], true, now()),
  (gen_random_uuid(), 'news.sports', 0, ARRAY['体育', '足球', '篮球'], true, now()),
  (gen_random_uuid(), 'news.entertainment', 0, ARRAY['娱乐', '明星', '电影'], true, now()),
  (gen_random_uuid(), 'news.health', 0, ARRAY['健康', '医疗', '疾病'], true, now()),
  (gen_random_uuid(), 'news.education', 0, ARRAY['教育', '学校', '考试'], true, now()),
  (gen_random_uuid(), 'news.international', 0, ARRAY['国际', '外交', '全球'], true, now());

-- 4. ak_contents
-- 生成50条内容，随机分配分类、作者、语言
DO $$
DECLARE
  i INT := 1;
  cat_ids uuid[] := ARRAY(SELECT id FROM public.ak_content_categories);
  lang_codes TEXT[] := ARRAY['zh-CN','en-US','ja-JP','ko-KR','fr-FR','de-DE','es-ES'];
  user_ids uuid[] := ARRAY(SELECT id FROM public.ak_users);
BEGIN
  WHILE i <= 50 LOOP
    INSERT INTO public.ak_contents (
      id, title, content, summary, author, source_url, original_language, category_id, tags, keywords, quality_score, published_at, status, created_at, updated_at
    ) VALUES (
      gen_random_uuid(),
      '测试资讯标题' || i,
      '这是第' || i || '条测试内容，内容丰富多样，适合测试。',
      '摘要内容' || i,
      'user' || ((i-1)%50+1),
      'https://example.com/news/' || i,
      lang_codes[(i%7)+1],
      cat_ids[(i%8)+1],
      ARRAY['标签A','标签B','标签C'],
      ARRAY['关键词1','关键词2'],
      round(random()*0.5+0.5,2),
      now() - (i || ' days')::interval,
      'published',
      now() - (i || ' days')::interval,
      now() - (i || ' days')::interval
    );
    i := i + 1;
  END LOOP;
END$$;

-- 5. ak_topics
DO $$
DECLARE
  i INT := 1;
  cat_ids uuid[] := ARRAY(SELECT id FROM public.ak_content_categories);
BEGIN
  WHILE i <= 50 LOOP
    INSERT INTO public.ak_topics (
      id, title, description, topic_type, status, cover_image_url, content_count, created_at, updated_at
    ) VALUES (
      gen_random_uuid(),
      '专题标题' || i,
      '这是第' || i || '个专题的描述。',
      'series',
      'active',
      'https://example.com/topic/cover/' || i || '.jpg',
      (random()*20)::int,
      now() - (i || ' days')::interval,
      now() - (i || ' days')::interval
    );
    i := i + 1;
  END LOOP;
END$$;

-- 6. ak_topic_contents
DO $$
DECLARE
  i INT := 1;
  topic_ids uuid[] := ARRAY(SELECT id FROM public.ak_topics);
  content_ids uuid[] := ARRAY(SELECT id FROM public.ak_contents);
BEGIN
  WHILE i <= 50 LOOP
    INSERT INTO public.ak_topic_contents (
      id, topic_id, content_id, display_order, editor_note, is_featured, added_at, created_at
    ) VALUES (
      gen_random_uuid(),
      topic_ids[(i%50)+1],
      content_ids[(i%50)+1],
      i,
      '编辑说明' || i,
      (i%2=0),
      now() - (i || ' days')::interval,
      now() - (i || ' days')::interval
    );
    i := i + 1;
  END LOOP;
END$$;

-- 7. ak_comments
DO $$
DECLARE
  i INT := 1;
  content_ids uuid[] := ARRAY(SELECT id FROM public.ak_contents);
  user_ids uuid[] := ARRAY(SELECT id FROM public.ak_users);
BEGIN
  WHILE i <= 50 LOOP
    INSERT INTO public.ak_comments (
      id, target_type, target_id, author_id, author_name, content, status, like_count, reply_count, level, created_at, updated_at
    ) VALUES (
      gen_random_uuid(),
      'content',
      content_ids[(i%50)+1],
      user_ids[(i%50)+1],
      '用户' || ((i-1)%50+1),
      '这是第' || i || '条评论内容。',
      'active',
      (random()*10)::int,
      (random()*5)::int,
      0,
      now() - (i || ' days')::interval,
      now() - (i || ' days')::interval
    );
    i := i + 1;
  END LOOP;
END$$;

-- 更多表可按需补充生成
