"""
Auto-generated logs resource.

DO NOT EDIT THIS FILE MANUALLY.
Run `python scripts/generate_resources.py` to regenerate.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ..client.base import BaseClient


class LogsResource:
    """
    Publishing logs for debugging.
    """

    def __init__(self, client: BaseClient) -> None:
        self._client = client

    def _build_params(self, **kwargs: Any) -> dict[str, Any]:
        """Build query parameters, filtering None values."""

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        return {to_camel(k): v for k, v in kwargs.items() if v is not None}

    def _build_payload(self, **kwargs: Any) -> dict[str, Any]:
        """Build request payload, filtering None values."""
        from datetime import datetime

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        result: dict[str, Any] = {}
        for k, v in kwargs.items():
            if v is None:
                continue
            if isinstance(v, datetime):
                result[to_camel(k)] = v.isoformat()
            else:
                result[to_camel(k)] = v
        return result

    def list_logs(
        self,
        *,
        status: str | None = None,
        platform: str | None = None,
        action: str | None = None,
        days: int | None = 7,
        limit: int | None = 50,
        skip: int | None = 0,
    ) -> dict[str, Any]:
        """Get publishing logs"""
        params = self._build_params(
            status=status,
            platform=platform,
            action=action,
            days=days,
            limit=limit,
            skip=skip,
        )
        return self._client._get("/v1/logs", params=params)

    def get_log(self, log_id: str) -> dict[str, Any]:
        """Get a single log entry"""
        return self._client._get(f"/v1/logs/{log_id}")

    def get_post_logs(self, post_id: str, *, limit: int | None = 50) -> dict[str, Any]:
        """Get logs for a specific post"""
        params = self._build_params(
            limit=limit,
        )
        return self._client._get(f"/v1/posts/{post_id}/logs", params=params)

    async def alist_logs(
        self,
        *,
        status: str | None = None,
        platform: str | None = None,
        action: str | None = None,
        days: int | None = 7,
        limit: int | None = 50,
        skip: int | None = 0,
    ) -> dict[str, Any]:
        """Get publishing logs (async)"""
        params = self._build_params(
            status=status,
            platform=platform,
            action=action,
            days=days,
            limit=limit,
            skip=skip,
        )
        return await self._client._aget("/v1/logs", params=params)

    async def aget_log(self, log_id: str) -> dict[str, Any]:
        """Get a single log entry (async)"""
        return await self._client._aget(f"/v1/logs/{log_id}")

    async def aget_post_logs(
        self, post_id: str, *, limit: int | None = 50
    ) -> dict[str, Any]:
        """Get logs for a specific post (async)"""
        params = self._build_params(
            limit=limit,
        )
        return await self._client._aget(f"/v1/posts/{post_id}/logs", params=params)
