-- 萌芽主页站点数据（SQLite）
PRAGMA foreign_keys = ON;

-- 基本个人信息
CREATE TABLE IF NOT EXISTS profile (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  favicon TEXT,
  nickname TEXT NOT NULL DEFAULT '',
  avatar TEXT,
  introduction TEXT,
  footer TEXT,
  site TEXT,
  homepage TEXT
);

-- 项目列表
CREATE TABLE IF NOT EXISTS project (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  sort_order INTEGER NOT NULL DEFAULT 0,
  title TEXT NOT NULL,
  description TEXT,
  link TEXT,
  icon TEXT,
  is_admin INTEGER NOT NULL DEFAULT 0 CHECK (is_admin IN (0, 1)),
  is_show INTEGER NOT NULL DEFAULT 1 CHECK (is_show IN (0, 1)),
  is_develop INTEGER NOT NULL DEFAULT 0 CHECK (is_develop IN (0, 1))
);

-- 项目分类 / 业务标签
CREATE TABLE IF NOT EXISTS project_tag (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  project_id INTEGER NOT NULL REFERENCES project (id) ON DELETE CASCADE,
  sort_order INTEGER NOT NULL DEFAULT 0,
  tag TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_project_tag_project ON project_tag (project_id, sort_order);

-- 项目技术栈标签（与 project_tag 分开维护）
CREATE TABLE IF NOT EXISTS project_tech_tag (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  project_id INTEGER NOT NULL REFERENCES project (id) ON DELETE CASCADE,
  sort_order INTEGER NOT NULL DEFAULT 0,
  tag TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_project_tech_tag_project ON project_tech_tag (project_id, sort_order);

-- 联系方式
CREATE TABLE IF NOT EXISTS contact (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  sort_order INTEGER NOT NULL DEFAULT 0,
  type TEXT NOT NULL,
  label TEXT,
  value TEXT,
  link TEXT,
  icon TEXT,
  is_show INTEGER NOT NULL DEFAULT 1 CHECK (is_show IN (0, 1))
);

-- 技术栈分类
CREATE TABLE IF NOT EXISTS techstack_section (
  id INTEGER PRIMARY KEY CHECK (id = 1),
  title TEXT NOT NULL DEFAULT '技术栈'
);

-- 技术栈项
CREATE TABLE IF NOT EXISTS techstack_item (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  sort_order INTEGER NOT NULL DEFAULT 0,
  name TEXT NOT NULL,
  link TEXT,
  svg TEXT,
  color TEXT,
  is_show INTEGER NOT NULL DEFAULT 1 CHECK (is_show IN (0, 1))
);

CREATE INDEX IF NOT EXISTS idx_techstack_item_order ON techstack_item (sort_order, id);
