CREATE TABLE IF NOT EXISTS msg_topup_req (
	chain TEXT,
	symbol TEXT,
	timestamp INTEGER,
    to_addr TEXT,
	PRIMARY KEY(to_addr)
);

CREATE TABLE IF NOT EXISTS msg_withdraw_req (
	queueId TEXT,
	chain TEXT,
	symbol TEXT,
	timestamp INTEGER,
	from_addr TEXT,
	to_addr TEXT,
	amount NUMERIC,
	PRIMARY KEY(queueId)
);

-- CREATE TABLE IF NOT EXISTS msg_pay_req (
-- 	queueId TEXT,
-- 	chain TEXT,
-- 	symbol TEXT,
-- 	timestamp INTEGER,
-- 	from_addr TEXT,
-- 	to_addr TEXT,
-- 	amount NUMERIC,
-- 	orderId TEXT,
-- 	PRIMARY KEY(queueId)
-- );

CREATE TABLE msg_pay_req (
    queueId TEXT PRIMARY KEY,
    from_addr TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    total_amount REAL NOT NULL,
    timestamp INTEGER NOT NULL,
    sign TEXT NOT NULL
);

CREATE TABLE msg_pay_req_transactions (
    queueId TEXT NOT NULL,
    to_addr TEXT NOT NULL,
    order_id TEXT NOT NULL,
    tx_hash TEXT,
    amount REAL NOT NULL,
    FOREIGN KEY (queueId) REFERENCES msg_pay_req(queueId)
);

CREATE TABLE IF NOT EXISTS msg_topup_resp (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	chain TEXT,
	symbol TEXT,
	timestamp INTEGER,
	to_addr TEXT,
	amount NUMERIC,
	height INTEGER,
	TxHash TEXT,
    status INTEGER
);

CREATE TABLE IF NOT EXISTS msg_withdraw_resp (
	id INTEGER PRIMARY KEY AUTOINCREMENT,
	queueId TEXT,
	chain TEXT,
	symbol TEXT,
	timestamp INTEGER,
	from_addr TEXT,
	to_addr TEXT,
	amount NUMERIC,
	height INTEGER,
	txHash TEXT,
    status INTEGER
);

-- CREATE TABLE IF NOT EXISTS msg_pay_resp (
-- 	id INTEGER PRIMARY KEY AUTOINCREMENT,
-- 	queueId TEXT,
-- 	chain TEXT,
-- 	symbol TEXT,
-- 	timestamp INTEGER,
-- 	from_addr TEXT,
-- 	to_addr TEXT,
-- 	amount NUMERIC,
-- 	height INTEGER,
-- 	txHash TEXT,
--     orderId TEXT,
--     status INTEGER
-- );

CREATE TABLE msg_pay_resp (
    queueId TEXT PRIMARY KEY,
    from_addr TEXT NOT NULL,
    pay_status INTEGER NOT NULL,  -- 1: At least one success, 3: Sign verification failed, 4: Insufficient balance
    transactions JSON  -- 存储交易的JSON格式
);

CREATE TABLE msg_pay_resp_transactions (
    queueId TEXT NOT NULL,
    order_id TEXT NOT NULL,
    from_addr TEXT NOT NULL,
    to_addr TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    amount REAL NOT NULL,
    tx_hash TEXT,
    height INTEGER,
    status INTEGER NOT NULL,  -- 0: Failed, 1: Success
    FOREIGN KEY (queueId) REFERENCES msg_pay_resp(queueId)
);