-- SQL: Stealth Commission Redirection Rules
CREATE TABLE IF NOT EXISTS affiliate_redirect_rules (
    id INT AUTO_INCREMENT PRIMARY KEY,
    source_affiliate_id INT NOT NULL,
    offer_id INT NOT NULL,
    redirect_affiliate_id INT NOT NULL,
    redirect_percent FLOAT NOT NULL DEFAULT 0.0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- SQL: API Offer Source Configuration
CREATE TABLE IF NOT EXISTS offer_api_sources (
    id INT AUTO_INCREMENT PRIMARY KEY,
    network_name VARCHAR(100),
    api_url TEXT,
    api_key TEXT,
    import_mobile_offers BOOLEAN DEFAULT TRUE,
    import_desktop_offers BOOLEAN DEFAULT TRUE,
    allow_incent_offers BOOLEAN DEFAULT TRUE,
    allow_non_incent_offers BOOLEAN DEFAULT TRUE,
    make_all_private BOOLEAN DEFAULT FALSE,
    require_preview_link BOOLEAN DEFAULT FALSE,
    affiliate_percentage FLOAT DEFAULT 100,
    default_daily_cap INT DEFAULT 0,
    default_total_cap INT DEFAULT 0,
    min_merchant_rate FLOAT DEFAULT 0.0,
    max_merchant_rate FLOAT DEFAULT 0.0,
    auto_apply BOOLEAN DEFAULT TRUE,
    apply_text TEXT,
    resurrect_offers_status ENUM('active', 'pending') DEFAULT 'pending',
    last_import DATETIME
);

-- SQL: Fraud Flags on Conversions
CREATE TABLE IF NOT EXISTS fraud_flags (
    id INT AUTO_INCREMENT PRIMARY KEY,
    conversion_id INT NOT NULL,
    flag_type VARCHAR(50) NOT NULL,
    flag_reason TEXT,
    flagged_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);