# Generated by ariadne-codegen
# Source: openhexa/cli/graphql/queries.graphql

from typing import Any, Dict, Optional, Union

from .base_client import BaseClient
from .base_model import UNSET, UnsetType
from .get_workspace_pipelines import GetWorkspacePipelines


def gql(q: str) -> str:
    return q


class Client(BaseClient):
    def get_workspace_pipelines(
        self,
        workspace_slug: str,
        name: Union[Optional[str], UnsetType] = UNSET,
        page: Union[Optional[int], UnsetType] = UNSET,
        per_page: Union[Optional[int], UnsetType] = UNSET,
        **kwargs: Any
    ) -> GetWorkspacePipelines:
        query = gql(
            """
            query getWorkspacePipelines($workspaceSlug: String!, $name: String, $page: Int = 1, $perPage: Int = 10) {
              pipelines(
                workspaceSlug: $workspaceSlug
                name: $name
                page: $page
                perPage: $perPage
              ) {
                totalPages
                items {
                  id
                  code
                  name
                  type
                  currentVersion {
                    id
                    name
                    versionNumber
                  }
                }
              }
            }
            """
        )
        variables: Dict[str, object] = {
            "workspaceSlug": workspace_slug,
            "name": name,
            "page": page,
            "perPage": per_page,
        }
        response = self.execute(
            query=query,
            operation_name="getWorkspacePipelines",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetWorkspacePipelines.model_validate(data)
