"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from jsonpath import JSONPath
from mesa_sdk import errors, models, utils
from mesa_sdk._hooks import HookContext
from mesa_sdk.types import OptionalNullable, UNSET
from mesa_sdk.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Awaitable, Dict, List, Mapping, Optional, Union


class Repos(BaseSDK):
    def create(
        self,
        *,
        org: str,
        name: str,
        default_branch: Optional[str] = "main",
        upstream: Optional[
            Union[
                models.PostByOrgReposUpstreamRequest,
                models.PostByOrgReposUpstreamRequestTypedDict,
            ]
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PostByOrgReposResponse:
        r"""Create repository

        Create a new repository in the organization

        :param org:
        :param name:
        :param default_branch:
        :param upstream:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PostByOrgReposRequest(
            org=org,
            body=models.PostByOrgReposRequestBody(
                name=name,
                default_branch=default_branch,
                upstream=utils.get_pydantic_model(
                    upstream, Optional[models.PostByOrgReposUpstreamRequest]
                ),
            ),
        )

        req = self._build_request(
            method="POST",
            path="/{org}/repos",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                True,
                "json",
                Optional[models.PostByOrgReposRequestBody],
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="postByOrgRepos",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "201", "application/json"):
            return unmarshal_json_response(models.PostByOrgReposResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposBadRequestErrorData, http_res
            )
            raise errors.PostByOrgReposBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposUnauthorizedErrorData, http_res
            )
            raise errors.PostByOrgReposUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposForbiddenErrorData, http_res
            )
            raise errors.PostByOrgReposForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposNotFoundErrorData, http_res
            )
            raise errors.PostByOrgReposNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposNotAcceptableErrorData, http_res
            )
            raise errors.PostByOrgReposNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposConflictErrorData, http_res
            )
            raise errors.PostByOrgReposConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposInternalServerErrorData, http_res
            )
            raise errors.PostByOrgReposInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def create_async(
        self,
        *,
        org: str,
        name: str,
        default_branch: Optional[str] = "main",
        upstream: Optional[
            Union[
                models.PostByOrgReposUpstreamRequest,
                models.PostByOrgReposUpstreamRequestTypedDict,
            ]
        ] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PostByOrgReposResponse:
        r"""Create repository

        Create a new repository in the organization

        :param org:
        :param name:
        :param default_branch:
        :param upstream:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PostByOrgReposRequest(
            org=org,
            body=models.PostByOrgReposRequestBody(
                name=name,
                default_branch=default_branch,
                upstream=utils.get_pydantic_model(
                    upstream, Optional[models.PostByOrgReposUpstreamRequest]
                ),
            ),
        )

        req = self._build_request_async(
            method="POST",
            path="/{org}/repos",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                True,
                "json",
                Optional[models.PostByOrgReposRequestBody],
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="postByOrgRepos",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "201", "application/json"):
            return unmarshal_json_response(models.PostByOrgReposResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposBadRequestErrorData, http_res
            )
            raise errors.PostByOrgReposBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposUnauthorizedErrorData, http_res
            )
            raise errors.PostByOrgReposUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposForbiddenErrorData, http_res
            )
            raise errors.PostByOrgReposForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposNotFoundErrorData, http_res
            )
            raise errors.PostByOrgReposNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposNotAcceptableErrorData, http_res
            )
            raise errors.PostByOrgReposNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposConflictErrorData, http_res
            )
            raise errors.PostByOrgReposConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgReposInternalServerErrorData, http_res
            )
            raise errors.PostByOrgReposInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def list(
        self,
        *,
        org: str,
        cursor: Optional[str] = None,
        limit: Optional[int] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.GetByOrgReposResponse]:
        r"""List repositories

        List all repositories in the organization

        :param org:
        :param cursor:
        :param limit:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgReposRequest(
            org=org,
            cursor=cursor,
            limit=limit,
        )

        req = self._build_request(
            method="GET",
            path="/{org}/repos",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgRepos",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        def next_func() -> Optional[models.GetByOrgReposResponse]:
            body = utils.unmarshal_json(http_res.text, Union[Dict[Any, Any], List[Any]])

            next_cursor = JSONPath("$.next_cursor").parse(body)

            if len(next_cursor) == 0:
                return None

            next_cursor = next_cursor[0]
            if next_cursor is None or str(next_cursor).strip() == "":
                return None
            results = JSONPath("$.repos").parse(body)
            if len(results) == 0 or len(results[0]) == 0:
                return None

            return self.list(
                org=org,
                cursor=next_cursor,
                limit=limit,
                retries=retries,
            )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return models.GetByOrgReposResponse(
                result=unmarshal_json_response(
                    models.GetByOrgReposResponseBody, http_res
                ),
                next=next_func,
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposBadRequestErrorData, http_res
            )
            raise errors.GetByOrgReposBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgReposUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposForbiddenErrorData, http_res
            )
            raise errors.GetByOrgReposForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposNotFoundErrorData, http_res
            )
            raise errors.GetByOrgReposNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgReposNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposConflictErrorData, http_res
            )
            raise errors.GetByOrgReposConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposInternalServerErrorData, http_res
            )
            raise errors.GetByOrgReposInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def list_async(
        self,
        *,
        org: str,
        cursor: Optional[str] = None,
        limit: Optional[int] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Optional[models.GetByOrgReposResponse]:
        r"""List repositories

        List all repositories in the organization

        :param org:
        :param cursor:
        :param limit:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgReposRequest(
            org=org,
            cursor=cursor,
            limit=limit,
        )

        req = self._build_request_async(
            method="GET",
            path="/{org}/repos",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgRepos",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        def next_func() -> Awaitable[Optional[models.GetByOrgReposResponse]]:
            body = utils.unmarshal_json(http_res.text, Union[Dict[Any, Any], List[Any]])

            async def empty_result():
                return None

            next_cursor = JSONPath("$.next_cursor").parse(body)

            if len(next_cursor) == 0:
                return empty_result()

            next_cursor = next_cursor[0]
            if next_cursor is None or str(next_cursor).strip() == "":
                return empty_result()
            results = JSONPath("$.repos").parse(body)
            if len(results) == 0 or len(results[0]) == 0:
                return empty_result()

            return self.list_async(
                org=org,
                cursor=next_cursor,
                limit=limit,
                retries=retries,
            )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return models.GetByOrgReposResponse(
                result=unmarshal_json_response(
                    models.GetByOrgReposResponseBody, http_res
                ),
                next=next_func,
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposBadRequestErrorData, http_res
            )
            raise errors.GetByOrgReposBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgReposUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposForbiddenErrorData, http_res
            )
            raise errors.GetByOrgReposForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposNotFoundErrorData, http_res
            )
            raise errors.GetByOrgReposNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgReposNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposConflictErrorData, http_res
            )
            raise errors.GetByOrgReposConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgReposInternalServerErrorData, http_res
            )
            raise errors.GetByOrgReposInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def get(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetByOrgByRepoResponse:
        r"""Get repository

        Get metadata for a specific repository

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgByRepoRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request(
            method="GET",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.GetByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.GetByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.GetByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.GetByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoConflictErrorData, http_res
            )
            raise errors.GetByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.GetByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def get_async(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetByOrgByRepoResponse:
        r"""Get repository

        Get metadata for a specific repository

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgByRepoRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request_async(
            method="GET",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.GetByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.GetByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.GetByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.GetByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoConflictErrorData, http_res
            )
            raise errors.GetByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.GetByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def delete(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DeleteByOrgByRepoResponse:
        r"""Delete repository

        Permanently delete a repository and all its data

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteByOrgByRepoRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request(
            method="DELETE",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DeleteByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoConflictErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def delete_async(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.DeleteByOrgByRepoResponse:
        r"""Delete repository

        Permanently delete a repository and all its data

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.DeleteByOrgByRepoRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request_async(
            method="DELETE",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="deleteByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.DeleteByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoConflictErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.DeleteByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.DeleteByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def update(
        self,
        *,
        org: str,
        repo: str,
        name: Optional[str] = None,
        upstream: OptionalNullable[
            Union[
                models.PatchByOrgByRepoUpstreamRequest,
                models.PatchByOrgByRepoUpstreamRequestTypedDict,
            ]
        ] = UNSET,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PatchByOrgByRepoResponse:
        r"""Update repository

        Update repository name or upstream configuration

        :param org:
        :param repo:
        :param name:
        :param upstream:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PatchByOrgByRepoRequest(
            org=org,
            repo=repo,
            body=models.PatchByOrgByRepoRequestBody(
                name=name,
                upstream=utils.get_pydantic_model(
                    upstream, OptionalNullable[models.PatchByOrgByRepoUpstreamRequest]
                ),
            ),
        )

        req = self._build_request(
            method="PATCH",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                True,
                "json",
                Optional[models.PatchByOrgByRepoRequestBody],
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="patchByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.PatchByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.PatchByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.PatchByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.PatchByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.PatchByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.PatchByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoConflictErrorData, http_res
            )
            raise errors.PatchByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.PatchByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def update_async(
        self,
        *,
        org: str,
        repo: str,
        name: Optional[str] = None,
        upstream: OptionalNullable[
            Union[
                models.PatchByOrgByRepoUpstreamRequest,
                models.PatchByOrgByRepoUpstreamRequestTypedDict,
            ]
        ] = UNSET,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PatchByOrgByRepoResponse:
        r"""Update repository

        Update repository name or upstream configuration

        :param org:
        :param repo:
        :param name:
        :param upstream:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PatchByOrgByRepoRequest(
            org=org,
            repo=repo,
            body=models.PatchByOrgByRepoRequestBody(
                name=name,
                upstream=utils.get_pydantic_model(
                    upstream, OptionalNullable[models.PatchByOrgByRepoUpstreamRequest]
                ),
            ),
        )

        req = self._build_request_async(
            method="PATCH",
            path="/{org}/{repo}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.body,
                False,
                True,
                "json",
                Optional[models.PatchByOrgByRepoRequestBody],
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="patchByOrgByRepo",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.PatchByOrgByRepoResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoBadRequestErrorData, http_res
            )
            raise errors.PatchByOrgByRepoBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoUnauthorizedErrorData, http_res
            )
            raise errors.PatchByOrgByRepoUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoForbiddenErrorData, http_res
            )
            raise errors.PatchByOrgByRepoForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoNotFoundErrorData, http_res
            )
            raise errors.PatchByOrgByRepoNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoNotAcceptableErrorData, http_res
            )
            raise errors.PatchByOrgByRepoNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoConflictErrorData, http_res
            )
            raise errors.PatchByOrgByRepoConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PatchByOrgByRepoInternalServerErrorData, http_res
            )
            raise errors.PatchByOrgByRepoInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def get_sync_status(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetByOrgByRepoSyncResponse:
        r"""Get sync status

        Get the sync status for a repository with upstream configured

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgByRepoSyncRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request(
            method="GET",
            path="/{org}/{repo}/sync",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgByRepoSync",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.GetByOrgByRepoSyncResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncBadRequestErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncForbiddenErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncNotFoundErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncConflictErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncInternalServerErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def get_sync_status_async(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.GetByOrgByRepoSyncResponse:
        r"""Get sync status

        Get the sync status for a repository with upstream configured

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.GetByOrgByRepoSyncRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request_async(
            method="GET",
            path="/{org}/{repo}/sync",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getByOrgByRepoSync",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.GetByOrgByRepoSyncResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncBadRequestErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncUnauthorizedErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncForbiddenErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncNotFoundErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncNotAcceptableErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncConflictErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.GetByOrgByRepoSyncInternalServerErrorData, http_res
            )
            raise errors.GetByOrgByRepoSyncInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    def sync(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PostByOrgByRepoSyncResponse:
        r"""Sync repository

        Trigger a sync from the upstream repository. Waits for sync to complete.

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PostByOrgByRepoSyncRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request(
            method="POST",
            path="/{org}/{repo}/sync",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="postByOrgByRepoSync",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.PostByOrgByRepoSyncResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncBadRequestErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncUnauthorizedErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncForbiddenErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncNotFoundErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncNotAcceptableErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncConflictErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncInternalServerErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)

    async def sync_async(
        self,
        *,
        org: str,
        repo: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.PostByOrgByRepoSyncResponse:
        r"""Sync repository

        Trigger a sync from the upstream repository. Waits for sync to complete.

        :param org:
        :param repo:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.PostByOrgByRepoSyncRequest(
            org=org,
            repo=repo,
        )

        req = self._build_request_async(
            method="POST",
            path="/{org}/{repo}/sync",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="postByOrgByRepoSync",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=[
                "400",
                "401",
                "403",
                "404",
                "406",
                "409",
                "4XX",
                "500",
                "5XX",
            ],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(models.PostByOrgByRepoSyncResponse, http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncBadRequestErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncBadRequestError(response_data, http_res)
        if utils.match_response(http_res, "401", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncUnauthorizedErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncUnauthorizedError(response_data, http_res)
        if utils.match_response(http_res, "403", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncForbiddenErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncForbiddenError(response_data, http_res)
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncNotFoundErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncNotFoundError(response_data, http_res)
        if utils.match_response(http_res, "406", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncNotAcceptableErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncNotAcceptableError(response_data, http_res)
        if utils.match_response(http_res, "409", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncConflictErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncConflictError(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.PostByOrgByRepoSyncInternalServerErrorData, http_res
            )
            raise errors.PostByOrgByRepoSyncInternalServerError(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.MesaDefaultError("API error occurred", http_res, http_res_text)

        raise errors.MesaDefaultError("Unexpected response received", http_res)
