# Copyright (c) 2025, JINGROW and contributors
# For license information, please see license.txt

"""
Query Report whitelist functions - Forward to SaaS using unified HTTP client
"""

import jingrow
import logging
from jingrow.utils.auth import saas_post

logger = logging.getLogger(__name__)


@jingrow.whitelist()
def run(**kwargs):
    """Run query report - Forward to SaaS"""
    resp = saas_post('/api/action/jingrow.desk.query_report.run', json=kwargs)
    if resp.status_code == 200:
        return resp.json().get("message", {})
    logger.error(f"[query_report.run] SaaS error: {resp.status_code}")
    return {}


@jingrow.whitelist()
def get_script(**kwargs):
    """Get report script - Forward to SaaS"""
    resp = saas_post('/api/action/jingrow.desk.query_report.get_script', json=kwargs)
    if resp.status_code == 200:
        return resp.json().get("message", {})
    logger.error(f"[query_report.get_script] SaaS error: {resp.status_code}")
    return {}
