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

"""
Desktop 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 get_workspace_sidebar_items(**kwargs):
    """Get workspace sidebar items - Forward to SaaS"""
    resp = saas_post('/api/action/jingrow.desk.desktop.get_workspace_sidebar_items', json=kwargs)
    if resp.status_code == 200:
        return resp.json().get("message", {})
    logger.error(f"[get_workspace_sidebar_items] SaaS error: {resp.status_code}")
    return {}


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