-- table users (sederhana)
CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(100) NOT NULL,
  password VARCHAR(255) NOT NULL,
  saldo BIGINT DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- topup_requests / orders
CREATE TABLE topup_requests (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  merchant_ref VARCHAR(100) NOT NULL,      -- unik untuk merchant
  tripay_trx_id VARCHAR(100) DEFAULT NULL, -- id transaksi dari Tripay (jika ada)
  amount BIGINT NOT NULL,
  method VARCHAR(50) DEFAULT NULL,         -- misal 'BRI', 'VA', dsb
  payment_url TEXT DEFAULT NULL,           -- url pembayaran
  status ENUM('pending','paid','expired','failed') DEFAULT 'pending',
  raw_response TEXT,                       -- simpan response Tripay utk debug
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);