import os
import json
import logging
import sys
from dotenv import load_dotenv
load_dotenv(override=True)
from superoffice_client import SuperOfficeClient

logging.basicConfig(level=logging.INFO)
sys.stdout.reconfigure(line_buffering=True)

def check_crmscript():
    client = SuperOfficeClient()
    
    print(f"🚀 Checking CRMScript capability...")
    
    # 1. Check if we can list scripts
    try:
        # Agents/CRMScript/GetCRMScripts
        res = client._post("Agents/CRMScript/GetCRMScripts", payload={"CRMScriptIds": []}) # Empty array usually gets all or error
        if res:
            print(f"✅ Can access CRMScripts. Response type: {type(res)}")
        else:
            # Try GET Archive
            print("⚠️ Agent access failed/empty. Trying Archive...")
            res = client._get("Archive/dynamic?$select=all&$top=1&entity=crmscript")
            if res:
                 print(f"✅ CRMScript Entity found in Archive.")
            else:
                 print(f"❌ CRMScript Entity NOT found in Archive.")
                 
    except Exception as e:
        print(f"❌ Exception checking CRMScript: {e}")

if __name__ == "__main__":
    check_crmscript()