-- 创建 sys_user 表
CREATE TABLE IF NOT EXISTS sys_user
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    username    TEXT NOT NULL,
    nickname    TEXT,
    password    TEXT NOT NULL,
    role_id     INTEGER,
    is_deleted  TINYINT DEFAULT 0,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 插入测试数据
INSERT INTO sys_user (username, nickname, password, role_id, is_deleted)
VALUES ('admin', 'Admin', '12345', 1, 0),
       ('john_doe', 'John Doe', 'password123', 2, 0),
       ('test', 'test', 'test123', 3, 0);


-- 创建 sys_role 表
CREATE TABLE IF NOT EXISTS sys_role
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT NOT NULL,
    code        TEXT NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 插入角色数据
INSERT INTO sys_role (name, code)
VALUES ('管理员', 'ADMIN'),
       ('普通用户', 'USER'),
       ('测试用户', 'TEST');

-- 创建 matrix 基质类型表
CREATE TABLE IF NOT EXISTS matrix
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 创建 matrix_craft 基质工艺表
CREATE TABLE IF NOT EXISTS matrix_craft
(
    id                      INTEGER PRIMARY KEY AUTOINCREMENT,
    name                    TEXT NOT NULL,
    matrix_id               INTEGER NOT NULL,
    route_type              INTEGER,
    z_height                INTEGER,
    nitrogen_flow_velocity  INTEGER,
    nitrogen_air_pressure   INTEGER,
    matrix_flow_velocity    INTEGER,
    voltage                 INTEGER,
    movement_speed          INTEGER,
    space                   INTEGER,
    create_user             INTEGER,
    create_time             TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time             TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 创建 syringe 注射器表
CREATE TABLE IF NOT EXISTS syringe
(
    id                INTEGER PRIMARY KEY AUTOINCREMENT,
    flow_rate         INTEGER,
    fluid_volume      INTEGER,
    run_time          INTEGER,
    cycle_intervals   INTEGER
);

-- 创建 operation_log 操作记录表
CREATE TABLE IF NOT EXISTS operation_log
(
    id                INTEGER PRIMARY KEY AUTOINCREMENT,
    matrix_craft_id   INTEGER,
    matrix_info       TEXT,
    status            INTEGER,
    create_user       INTEGER,
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 创建 sys_settings 系统配置表
CREATE TABLE IF NOT EXISTS sys_settings
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    parent_id   INTEGER,
    name        TEXT NOT NULL,
    code        TEXT,
    value       TEXT
);
