#!/usr/bin/env python3
"""
============================================
Work.Ink Offer SDK - Python Example
============================================
Run: python example.py
Note: Place work-ink-offer-sdk.dll in same folder
"""

import ctypes
import os
import sys

def main():
    print("Work.Ink Offer SDK - Python Example")
    print("=" * 40)
    print()
    
    # Load the DLL
    try:
        # Try to load from current directory
        dll_path = os.path.join(os.path.dirname(__file__), "work-ink-offer-sdk.dll")
        if not os.path.exists(dll_path):
            dll_path = "work-ink-offer-sdk.dll"
        
        sdk = ctypes.CDLL(dll_path)
        
        # Define the function signature
        # int runOffer(int pubId)
        sdk.runOffer.argtypes = [ctypes.c_int]
        sdk.runOffer.restype = ctypes.c_int
        
    except OSError as e:
        print("ERROR: Could not load work-ink-offer-sdk.dll")
        print(f"Make sure the DLL is in the same folder as this script.")
        print(f"Error: {e}")
        sys.exit(1)
    
    # Replace 1 with your actual publisher ID
    publisher_id = 1
    
    print(f"Showing offer for publisher ID: {publisher_id}")
    
    # Call the SDK function
    result = sdk.runOffer(publisher_id)
    
    # Handle the result
    print(f"\nResult: {result}")
    
    if result == 1:
        print("✅ SUCCESS: User accepted and installer launched!")
        # Continue with your application...
    elif result == 0:
        print("⚠️ PARTIAL: Installer launch failed, browser opened")
        # Still count as acceptance, continue...
    elif result == -1:
        print("❌ DECLINED: User declined the offer")
        # User declined, continue with your app...
    elif result == -2:
        print("🚪 CLOSED: User closed the window")
        # User closed without decision...
    elif result == -3:
        print("🌐 API ERROR: Could not fetch offers")
        # Network error or no offers available...
    else:
        print("❓ UNKNOWN: Unexpected result")
    
    print("\nContinuing with application...")
    # Your application logic here

if __name__ == "__main__":
    main()

