"""
Queries API namespace.

AUTO-GENERATED by scripts/generate_sdk.py - DO NOT EDIT MANUALLY!
Regenerate with: python scripts/generate_sdk.py --category queries
"""
from __future__ import annotations

from typing import Any, Dict, List, Optional

from ._base import AsyncBaseAPI, BaseAPI


class QueriesAPI(BaseAPI):
    """Queries namespace: copy, delete, edit, execute, get, list, preview, save."""

    def copy(
        self,
        *,
        name: str,
        category: str,
        new_name: str,
        description: Optional[str] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Copy query

        Copy query with new name.

        Args:
        name: Source query name
        category: Query category
        new_name: New query name
        description: New description"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        params["new_name"] = new_name
        if description is not None:
            params["description"] = description
        return self._call("queries.copy", params=params, options=options, context=context)

    def delete(
        self,
        *,
        name: str,
        category: str,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Delete query

        Delete saved query.

        Args:
        name: Query name
        category: Query category"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        return self._call("queries.delete", params=params, options=options, context=context)

    def edit(
        self,
        *,
        name: str,
        category: str,
        definition: Optional[Dict[str, Any]] = None,
        items: Optional[List[Any]] = None,
        expression: Optional[str] = None,
        description: Optional[str] = None,
        tags: Optional[List[Any]] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Edit query

        Update existing query.

        Args:
        name: Query name
        category: Query category
        definition: New query definition
        items: New static items
        expression: New expression
        description: New description
        tags: New tags"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        if definition is not None:
            params["definition"] = definition
        if items is not None:
            params["items"] = items
        if expression is not None:
            params["expression"] = expression
        if description is not None:
            params["description"] = description
        if tags is not None:
            params["tags"] = tags
        return self._call("queries.edit", params=params, options=options, context=context)

    def execute(
        self,
        *,
        id: Optional[str] = None,
        query_id: Optional[str] = None,
        name: Optional[str] = None,
        category: Optional[str] = None,
        output_path: Optional[str] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
        response_format: Optional[str] = None,
    ) -> Any:
        """Execute query

        Execute saved query and return results.

        Args:
        id: Query ID
        query_id: Query ID (alias)
        name: Query name
        category: Query category
        output_path: Output file path"""
        params: Dict[str, Any] = {}
        if id is not None:
            params["id"] = id
        if query_id is not None:
            params["query_id"] = query_id
        if name is not None:
            params["name"] = name
        if category is not None:
            params["category"] = category
        if output_path is not None:
            params["output_path"] = output_path
        return self._call("queries.execute", params=params, options=options, context=context, response_format=response_format)

    def get(
        self,
        *,
        name: str,
        category: str,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Get saved query

        Get query by name.

        Args:
        name: Query name
        category: Query category"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        return self._call("queries.get", params=params, options=options, context=context)

    def list(
        self,
        *,
        category: Optional[str] = None,
        limit: Optional[int] = 100,
        offset: Optional[int] = 0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """List saved queries

        List user's saved queries.

        Args:
        category: Filter by category
        limit: Maximum results
        offset: Pagination offset"""
        params: Dict[str, Any] = {}
        if category is not None:
            params["category"] = category
        if limit is not None:
            params["limit"] = limit
        if offset is not None:
            params["offset"] = offset
        return self._call("queries.list", params=params, options=options, context=context)

    def preview(
        self,
        *,
        query: Dict[str, Any],
        limit: Optional[int] = 10,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
        response_format: Optional[str] = None,
    ) -> Any:
        """Preview query

        Preview query without saving.

        Args:
        query: Query definition
        limit: Maximum results"""
        params: Dict[str, Any] = {}
        params["query"] = query
        if limit is not None:
            params["limit"] = limit
        return self._call("queries.preview", params=params, options=options, context=context, response_format=response_format)

    def save(
        self,
        *,
        name: str,
        category: str,
        type_: Optional[str] = "dynamic",
        visibility: Optional[str] = "private",
        definition: Optional[Dict[str, Any]] = None,
        items: Optional[List[Any]] = None,
        expression: Optional[str] = None,
        description: Optional[str] = "",
        tags: Optional[List[Any]] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Save query

        Save a new query.

        Args:
        name: Query name
        category: Query category
        type_: Query type: dynamic|static|expression
        visibility: Visibility: private|workspace
        definition: Query definition (for dynamic)
        items: Static items (for static)
        expression: Expression (for expression type)
        description: Description
        tags: Tags"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        if type_ is not None:
            params["type"] = type_
        if visibility is not None:
            params["visibility"] = visibility
        if definition is not None:
            params["definition"] = definition
        if items is not None:
            params["items"] = items
        if expression is not None:
            params["expression"] = expression
        if description is not None:
            params["description"] = description
        if tags is not None:
            params["tags"] = tags
        return self._call("queries.save", params=params, options=options, context=context)



class AsyncQueriesAPI(AsyncBaseAPI):
    """Queries namespace: copy, delete, edit, execute, get, list, preview, save."""

    async def copy(
        self,
        *,
        name: str,
        category: str,
        new_name: str,
        description: Optional[str] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Copy query

        Copy query with new name.

        Args:
        name: Source query name
        category: Query category
        new_name: New query name
        description: New description"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        params["new_name"] = new_name
        if description is not None:
            params["description"] = description
        return await self._call("queries.copy", params=params, options=options, context=context)

    async def delete(
        self,
        *,
        name: str,
        category: str,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Delete query

        Delete saved query.

        Args:
        name: Query name
        category: Query category"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        return await self._call("queries.delete", params=params, options=options, context=context)

    async def edit(
        self,
        *,
        name: str,
        category: str,
        definition: Optional[Dict[str, Any]] = None,
        items: Optional[List[Any]] = None,
        expression: Optional[str] = None,
        description: Optional[str] = None,
        tags: Optional[List[Any]] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Edit query

        Update existing query.

        Args:
        name: Query name
        category: Query category
        definition: New query definition
        items: New static items
        expression: New expression
        description: New description
        tags: New tags"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        if definition is not None:
            params["definition"] = definition
        if items is not None:
            params["items"] = items
        if expression is not None:
            params["expression"] = expression
        if description is not None:
            params["description"] = description
        if tags is not None:
            params["tags"] = tags
        return await self._call("queries.edit", params=params, options=options, context=context)

    async def execute(
        self,
        *,
        id: Optional[str] = None,
        query_id: Optional[str] = None,
        name: Optional[str] = None,
        category: Optional[str] = None,
        output_path: Optional[str] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
        response_format: Optional[str] = None,
    ) -> Any:
        """Execute query

        Execute saved query and return results.

        Args:
        id: Query ID
        query_id: Query ID (alias)
        name: Query name
        category: Query category
        output_path: Output file path"""
        params: Dict[str, Any] = {}
        if id is not None:
            params["id"] = id
        if query_id is not None:
            params["query_id"] = query_id
        if name is not None:
            params["name"] = name
        if category is not None:
            params["category"] = category
        if output_path is not None:
            params["output_path"] = output_path
        return await self._call("queries.execute", params=params, options=options, context=context, response_format=response_format)

    async def get(
        self,
        *,
        name: str,
        category: str,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Get saved query

        Get query by name.

        Args:
        name: Query name
        category: Query category"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        return await self._call("queries.get", params=params, options=options, context=context)

    async def list(
        self,
        *,
        category: Optional[str] = None,
        limit: Optional[int] = 100,
        offset: Optional[int] = 0,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """List saved queries

        List user's saved queries.

        Args:
        category: Filter by category
        limit: Maximum results
        offset: Pagination offset"""
        params: Dict[str, Any] = {}
        if category is not None:
            params["category"] = category
        if limit is not None:
            params["limit"] = limit
        if offset is not None:
            params["offset"] = offset
        return await self._call("queries.list", params=params, options=options, context=context)

    async def preview(
        self,
        *,
        query: Dict[str, Any],
        limit: Optional[int] = 10,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
        response_format: Optional[str] = None,
    ) -> Any:
        """Preview query

        Preview query without saving.

        Args:
        query: Query definition
        limit: Maximum results"""
        params: Dict[str, Any] = {}
        params["query"] = query
        if limit is not None:
            params["limit"] = limit
        return await self._call("queries.preview", params=params, options=options, context=context, response_format=response_format)

    async def save(
        self,
        *,
        name: str,
        category: str,
        type_: Optional[str] = "dynamic",
        visibility: Optional[str] = "private",
        definition: Optional[Dict[str, Any]] = None,
        items: Optional[List[Any]] = None,
        expression: Optional[str] = None,
        description: Optional[str] = "",
        tags: Optional[List[Any]] = None,
        options: Optional[Dict[str, Any]] = None,
        context: Optional[Dict[str, Any]] = None,
    ) -> Any:
        """Save query

        Save a new query.

        Args:
        name: Query name
        category: Query category
        type_: Query type: dynamic|static|expression
        visibility: Visibility: private|workspace
        definition: Query definition (for dynamic)
        items: Static items (for static)
        expression: Expression (for expression type)
        description: Description
        tags: Tags"""
        params: Dict[str, Any] = {}
        params["name"] = name
        params["category"] = category
        if type_ is not None:
            params["type"] = type_
        if visibility is not None:
            params["visibility"] = visibility
        if definition is not None:
            params["definition"] = definition
        if items is not None:
            params["items"] = items
        if expression is not None:
            params["expression"] = expression
        if description is not None:
            params["description"] = description
        if tags is not None:
            params["tags"] = tags
        return await self._call("queries.save", params=params, options=options, context=context)


