-- migrations.sql
CREATE TABLE payments (
    id INT AUTO_INCREMENT PRIMARY KEY,
    client_token VARCHAR(128) NOT NULL, -- token/session issued to client
    user_id INT NULL, -- optional: your app's user id
    amount INT NOT NULL, -- amount in IRR (Rials)
    authority VARCHAR(128) NULL,
    ref_id VARCHAR(128) NULL,
    status VARCHAR(32) NOT NULL DEFAULT 'created', -- created, pending, verified, failed
    error_code INT NULL,
    error_message TEXT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE INDEX idx_authority ON payments(authority);
CREATE INDEX idx_client_token ON payments(client_token);
