-- 代付请求表 + 订单表代付字段
-- 执行：mysql -u user -p db < soul-api/scripts/add-gift-pay-requests.sql
-- 注：orders 表新增字段由 GORM AutoMigrate 自动添加；若需手动执行：
-- ALTER TABLE orders ADD COLUMN gift_pay_request_id VARCHAR(50) DEFAULT NULL;
-- ALTER TABLE orders ADD COLUMN payer_user_id VARCHAR(50) DEFAULT NULL;

CREATE TABLE IF NOT EXISTS gift_pay_requests (
  id VARCHAR(50) PRIMARY KEY,
  request_sn VARCHAR(32) NOT NULL UNIQUE,
  initiator_user_id VARCHAR(50) NOT NULL,
  product_type VARCHAR(30) NOT NULL,
  product_id VARCHAR(50) NOT NULL DEFAULT '',
  amount DECIMAL(10,2) NOT NULL,
  description VARCHAR(200) NOT NULL DEFAULT '',
  status VARCHAR(20) NOT NULL DEFAULT 'pending',
  payer_user_id VARCHAR(50) DEFAULT NULL,
  order_id VARCHAR(50) DEFAULT NULL,
  expire_at DATETIME NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_initiator (initiator_user_id),
  INDEX idx_payer (payer_user_id),
  INDEX idx_status (status),
  INDEX idx_request_sn (request_sn)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
