-- Tabela de vouchers/giftcards para o sistema de recompensas
CREATE TABLE IF NOT EXISTS vouchers (
    id INT AUTO_INCREMENT PRIMARY KEY,
    voucher_type VARCHAR(50) NOT NULL COMMENT 'Tipo: ifood, uber, playstation, amazon, netflix, spotify, google_play, apple, steam, xbox',
    voucher_code VARCHAR(255) NOT NULL COMMENT 'Código do voucher/giftcard',
    coin_cost INT NOT NULL DEFAULT 100 COMMENT 'Custo em moedas',
    description VARCHAR(500) NULL COMMENT 'Descrição opcional do voucher',
    is_used TINYINT(1) NOT NULL DEFAULT 0 COMMENT '0=disponível, 1=usado',
    used_by_user_id INT NULL COMMENT 'ID do usuário que usou',
    used_at DATETIME NULL COMMENT 'Data/hora do resgate',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (used_by_user_id) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_voucher_type (voucher_type),
    INDEX idx_is_used (is_used),
    INDEX idx_used_by (used_by_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
