CREATE TABLE IF NOT EXISTS tax_transactions (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    ref_no VARCHAR(64) NOT NULL,
    request_hash CHAR(40) NOT NULL,
    industry_type VARCHAR(32) NOT NULL,
    request_body MEDIUMTEXT NOT NULL,
    response_body MEDIUMTEXT NULL,
    status ENUM('Processing', 'Success', 'Failed') NOT NULL DEFAULT 'Processing',
    qr_url VARCHAR(255) NULL,
    attempts INT NOT NULL DEFAULT 0,
    last_error TEXT NULL,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL,
    PRIMARY KEY (id),
    UNIQUE KEY uk_tax_transactions_ref_no (ref_no),
    KEY idx_tax_transactions_request_hash (request_hash),
    KEY idx_tax_transactions_status_updated (status, updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

