

CREATE TABLE balances (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  amount DECIMAL(10,2) DEFAULT 0,
  FOREIGN KEY (user_id) REFERENCES web_users(id)
);

CREATE TABLE vpn_prices (
  id INT AUTO_INCREMENT PRIMARY KEY,
  price_per_month DECIMAL(10,2) NOT NULL DEFAULT 20000
);

CREATE TABLE vpn_accounts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT,
  server_id INT,
  username VARCHAR(50),
  vpn_ip VARCHAR(20),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES web_users(id),
  FOREIGN KEY (server_id) REFERENCES vpn_servers(id)
);

INSERT INTO vpn_prices (price_per_month) VALUES (20000);

CREATE TABLE topup_requests (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  amount DECIMAL(10,2) NOT NULL,
  method ENUM('tripay','manual') DEFAULT 'manual',
  status ENUM('pending','success','failed') DEFAULT 'pending',
  reference VARCHAR(100),
  note TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (user_id) REFERENCES web_users(id)
);

ALTER TABLE vpn_accounts ADD COLUMN expired_at DATETIME;
