"""
EXAMPLE: How the remote bot.py likely works

This shows what the organizers probably changed for the remote challenge.
The local version has FLAG defined but never used - this is intentional!
On the remote server, they would modify visit_url() to actually SET the flag.
"""

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

BASE_URL = "http://127.0.0.1:5000"
FLAG = "uoftctf{fake_flag}"  # On remote: FLAG = os.environ.get('FLAG')


def visit_url(target_url):
    """
    LOCAL VERSION (current): FLAG is never used
    REMOTE VERSION (likely): FLAG is set as cookie before visiting
    """
    options = Options()
    options.add_argument("--headless=true")
    options.add_argument("--disable-gpu")
    options.add_argument("--no-sandbox")
    driver = webdriver.Chrome(options=options)
    try:
        driver.get(target_url)

        # ========================================
        # THIS IS WHAT THE REMOTE VERSION PROBABLY ADDS:
        # ========================================

        # Option 1: Set FLAG as a cookie (MOST LIKELY)
        # driver.add_cookie({
        #     'name': 'flag',
        #     'value': FLAG,
        #     'domain': '127.0.0.1'
        # })
        # driver.refresh()  # Refresh so cookie is sent

        # Option 2: Set FLAG in localStorage
        # driver.execute_script(f"localStorage.setItem('flag', '{FLAG}')")

        # Option 3: Navigate to URL with flag as parameter
        # driver.get(target_url + f"?flag={FLAG}")

        # ========================================

        time.sleep(30)
    finally:
        driver.quit()


# TO TEST LOCALLY WITH FLAG WORKING:
# Uncomment one of the options above and run:
# python bot_remote_example.py
