-- 用户 表
CREATE TABLE IF NOT EXISTS user
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    username    TEXT UNIQUE,
    nickname    TEXT,
    password    TEXT,
    role        TEXT,
    fixed_user  TEXT,
    deleted     TEXT,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT OR IGNORE INTO user (username, nickname, password, role, fixed_user, deleted)
VALUES ('admin', 'Admin', '123456', 'ADMIN', 'ENABLE', 'DISABLE'),
       ('test', 'test', '123456', 'ADMIN', 'ENABLE', 'DISABLE');

-- ores 矿石 表
CREATE TABLE IF NOT EXISTS ores
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 设备位置 表
CREATE TABLE IF NOT EXISTS device_position
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT,
    code        TEXT NOT NULL UNIQUE,
    type        TEXT,
    position    TEXT,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 系统配置 表
CREATE TABLE IF NOT EXISTS system_config
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        TEXT,
    code        TEXT NOT NULL UNIQUE,
    value       TEXT,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO system_config (id, name, code, value)
VALUES ('1', '稀硝酸容量与泵行程比率', 'scale_thin', '100'),
       ('2', '浓硝酸容量与泵行程比率', 'scale_thick', '100'),
       ('3', '蒸馏水容量与泵行程比率', 'scale_water', '100'),
       ('4', '废液容量与泵行程比率', 'scale_waste', '100');


-- 系统日志 表
CREATE TABLE IF NOT EXISTS system_log
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    title       TEXT NOT NULL,
    content     TEXT NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- 设备参数 表
CREATE TABLE IF NOT EXISTS device_param_config
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    mid         text,
    reg_index   text,
    reg_val     INTEGER,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);

-- crafts 工艺 表
CREATE TABLE IF NOT EXISTS crafts
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    steps       TEXT,
    ores_id     INTEGER,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 实验 表
CREATE TABLE IF NOT EXISTS tasks
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    start_time  TIMESTAMP,
    end_time    TIMESTAMP,
    status      INTEGER,
    create_user INTEGER,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    is_deleted  INTEGER
);

-- 实验步骤记录 表
CREATE TABLE IF NOT EXISTS task_steps
(
    id               INTEGER PRIMARY KEY AUTOINCREMENT,
    task_id          INTEGER,
    step_description TEXT,
    create_time      TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- container 容器 表
CREATE TABLE IF NOT EXISTS container
(
    id             INTEGER PRIMARY KEY AUTOINCREMENT,
    type           INTEGER,
    code           TEXT,
    solution_id    INTEGER,
    pump_id        TEXT,
    capacity_total INTEGER,
    capacity_used  INTEGER,
    filled         REAL,
    create_time    TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time    TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT OR IGNORE INTO container (id, type, code, solution_id, pump_id, capacity_total, capacity_used)
VALUES (1, 0, 'container_01', 1, 'liquid_pump', 5000, 0),
       (2, 0, 'container_02', 2, 'liquid_pump', 5000, 2500),
       (3, 0, 'container_03', 3, 'liquid_pump', 5000, 2600),
       (4, 1, 'container_04', 4, 'liquid_pump', 5000, 0);


-- solutions 溶液 表
CREATE TABLE IF NOT EXISTS solutions
(
    id          INTEGER PRIMARY KEY AUTOINCREMENT,
    name        VARCHAR NOT NULL,
    code        VARCHAR NOT NULL,
    create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT OR IGNORE INTO solutions (id, name, code, create_time, update_time)
VALUES (1, '稀硝酸', 'thin', '2025-02-18 02:44:07', '2025-02-18 02:44:07'),
       (2, '浓硝酸', 'thick', '2025-02-18 02:44:07', '2025-02-18 02:44:07'),
       (3, '蒸馏水', 'water', '2025-02-18 02:44:07', '2025-02-18 02:44:07'),
       (4, '废液', 'waste', '2025-02-18 02:46:23', '2025-02-18 02:46:23');