#  Copyright © 2025 Bentley Systems, Incorporated
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#      http://www.apache.org/licenses/LICENSE-2.0
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
"""
Block Model API
=============


    The Block Model API provides the ability to manage and report on block models in your Evo workspaces. Enable your
    product with Evo connected workflows by integrating with the Seequent Block Model API.

    The Block Model API supports a range of sub-blocking options, and both full and partial updates to block models,
    including updates of specified columns and/or sub-volumes. Block models are versioned, and the service supports
    reporting on the material content of current or previous versions, and comparing the content between versions of
    a block model.

    For more information on the Block Model API, see [Overview](/docs/guides/blockmodel/), or the API references here.


This code is generated from the OpenAPI specification for Block Model API.
API version: 1.41.3
"""

from evo.common.connector import APIConnector
from evo.common.data import RequestMethod
from evo.common.utils import get_header_metadata

from ..models import *  # noqa: F403

__all__ = ["MetadataApi"]


class MetadataApi:
    """API client for the Metadata endpoint.

    NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.

    :param connector: Client for communicating with the API.
    """

    def __init__(self, connector: APIConnector):
        self.connector = connector

    async def list_block_models(
        self,
        workspace_id: str,
        org_id: str,
        deleted: bool | None = None,
        order_by: str | None = None,
        offset: int | None = None,
        limit: int | None = None,
        additional_headers: dict[str, str] | None = None,
        request_timeout: int | float | tuple[int | float, int | float] | None = None,
    ) -> PaginatedResponseBlockModel:  # noqa: F405
        """List all block models in a workspace

        Gets a paginated list of all block models in a workspace identified by `workspace_id`. By retrieving this list, you can obtain the `bm_id` value for a given model, which can then be used in subsequent API requests to upload or download data, along with performing other operations.  The list is ordered from the most recently updated block model to the least recently updated block model. By default, the list is ordered from the most recently updated block model to the least recently updated block model. If a `sort` query parameter is specified, the list will be ordered according to the specified field.  This endpoint is paginated, therefore by default this lists at most the first 50 block models. To get other block models, use the `offset` and `limit` query parameters to select the desired part of the list. An `offset` beyond the total number of block models in the workspace will result in an empty `results` list. The `limit` must be an integer from 1 to 100. The response includes `total`, which is the total number of block models within the list.  All workspace roles can use this endpoint.

        :param workspace_id: ID of the workspace this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'860be2f5-fe06-4c1b-ac8b-7d34d2b6d2ef'`
        :param org_id: ID of the organization this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'bf1a040c-8c58-4bc2-bec2-c5ae7de8bd84'`
        :param deleted: (optional)  An optional boolean parameter specifying whether to list only deleted block models.  - If set to `true`, the response will only list block models that were deleted via the 'Delete a block model' endpoint. This list will not include block models that are within deleted workspaces.  - By default, or if set to `false`, the response will only list non-deleted block models within non-deleted workspaces.
            Example: `False`
        :param order_by: (optional)  An optional query parameter specifying how the results should be sorted. If not provided, results are sorted by `last_updated_at` in descending order.  This is a comma-separated list of fields; allowed field names are `name`, `created_at`, and `last_updated_at`. You cannot specify the same field twice.  By default, results are sorted in ascending order. To explicitly specify the sort order for a field, you can prefix its name with `asc:` (ascending) or `desc:` (descending). For example, `order_by=desc:created_at` will sort block models by time created in descending order.
            Example: `'order_by_example'`
        :param offset: (optional) Index of the first item to return.
            Example: `0`
        :param limit: (optional) Maximum number of items to return from the list. Must be greater than 0 and less than or equal to 100.
            Example: `50`
        :param additional_headers: (optional) Additional headers to send with the request.
        :param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
            total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

        :return: Returns the result object.

        :raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
        :raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
        :raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
        :raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
        :raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
            400 and 599, and the body of the response contains a descriptive `type` parameter.
        :raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
            and 599, and the body of the response does not contain a `type` parameter.
        :raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
            type in `response_types_map`.
        """
        # Prepare the path parameters.
        _path_params = {
            "workspace_id": workspace_id,
            "org_id": org_id,
        }

        # Prepare the query parameters.
        _query_params = {}
        if deleted is not None:
            _query_params["deleted"] = deleted
        if order_by is not None:
            _query_params["order_by"] = order_by
        if offset is not None:
            _query_params["offset"] = offset
        if limit is not None:
            _query_params["limit"] = limit

        # Prepare the header parameters.
        _header_params = {
            "Accept": "application/json",
        } | get_header_metadata(__name__)
        if additional_headers is not None:
            _header_params.update(additional_headers)

        # Define the collection formats.
        _collection_formats = {}

        _response_types_map = {
            "200": PaginatedResponseBlockModel,  # noqa: F405
        }

        return await self.connector.call_api(
            method=RequestMethod.GET,
            resource_path="/blockmodel/orgs/{org_id}/workspaces/{workspace_id}/block-models",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            collection_formats=_collection_formats,
            response_types_map=_response_types_map,
            request_timeout=request_timeout,
        )

    async def list_block_models_across_workspaces(
        self,
        org_id: str,
        deleted: bool | None = None,
        order_by: str | None = None,
        offset: int | None = None,
        limit: int | None = None,
        additional_headers: dict[str, str] | None = None,
        request_timeout: int | float | tuple[int | float, int | float] | None = None,
    ) -> PaginatedResponseBlockModel:  # noqa: F405
        """List all block models in an organization

        Gets a paginated list of all block models across all workspaces that are accessible in the organization identified by `org_id`. By retrieving this list, you can obtain the `bm_id` value for a given model, which can then be used in subsequent API requests to upload or download data, along with performing other operations.  By default, the list is ordered from the most recently updated block model to the least recently updated block model. If a `sort` query parameter is specified, the list will be ordered according to the specified field.  This endpoint is paginated, therefore by default this lists at most the first 50 block models. To get other block models, use the `offset` and `limit` query parameters to select the desired part of the list. An `offset` beyond the total number of block models across all workspaces will result in an empty `results` list. The `limit` must be an integer from 1 to 100. The response includes `total`, which is the total number of block models within the list.  All workspace roles can use this endpoint.

        :param org_id: ID of the organization this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'bf1a040c-8c58-4bc2-bec2-c5ae7de8bd84'`
        :param deleted: (optional)  An optional boolean parameter specifying whether to list only deleted block models.  - If set to `true`, the response will only list block models that were deleted via the 'Delete a block model' endpoint. This list will not include block models that are within deleted workspaces.  - By default, or if set to `false`, the response will only list non-deleted block models within non-deleted workspaces.
            Example: `False`
        :param order_by: (optional)  An optional query parameter specifying how the results should be sorted. If not provided, results are sorted by `last_updated_at` in descending order.  This is a comma-separated list of fields; allowed field names are `name`, `created_at`, and `last_updated_at`. You cannot specify the same field twice.  By default, results are sorted in ascending order. To explicitly specify the sort order for a field, you can prefix its name with `asc:` (ascending) or `desc:` (descending). For example, `order_by=desc:created_at` will sort block models by time created in descending order.
            Example: `'order_by_example'`
        :param offset: (optional) Index of the first item to return.
            Example: `0`
        :param limit: (optional) Maximum number of items to return from the list. Must be greater than 0 and less than or equal to 100.
            Example: `50`
        :param additional_headers: (optional) Additional headers to send with the request.
        :param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
            total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

        :return: Returns the result object.

        :raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
        :raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
        :raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
        :raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
        :raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
            400 and 599, and the body of the response contains a descriptive `type` parameter.
        :raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
            and 599, and the body of the response does not contain a `type` parameter.
        :raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
            type in `response_types_map`.
        """
        # Prepare the path parameters.
        _path_params = {
            "org_id": org_id,
        }

        # Prepare the query parameters.
        _query_params = {}
        if deleted is not None:
            _query_params["deleted"] = deleted
        if order_by is not None:
            _query_params["order_by"] = order_by
        if offset is not None:
            _query_params["offset"] = offset
        if limit is not None:
            _query_params["limit"] = limit

        # Prepare the header parameters.
        _header_params = {
            "Accept": "application/json",
        } | get_header_metadata(__name__)
        if additional_headers is not None:
            _header_params.update(additional_headers)

        # Define the collection formats.
        _collection_formats = {}

        _response_types_map = {
            "200": PaginatedResponseBlockModel,  # noqa: F405
        }

        return await self.connector.call_api(
            method=RequestMethod.GET,
            resource_path="/blockmodel/orgs/{org_id}/block-models",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            collection_formats=_collection_formats,
            response_types_map=_response_types_map,
            request_timeout=request_timeout,
        )

    async def retrieve_block_model(
        self,
        bm_id: str,
        workspace_id: str,
        org_id: str,
        deleted: bool | None = None,
        additional_headers: dict[str, str] | None = None,
        request_timeout: int | float | tuple[int | float, int | float] | None = None,
    ) -> BlockModel:  # noqa: F405
        """Get a block model's metadata

        Gets the details of the block model for the given `bm_id`.  All workspace roles can use this endpoint.

        :param bm_id: ID of the block model this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'e3c277c2-edc6-4a7a-8380-251dd19231f2'`
        :param workspace_id: ID of the workspace this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'860be2f5-fe06-4c1b-ac8b-7d34d2b6d2ef'`
        :param org_id: ID of the organization this call is scoped to. Represented as a v4 UUID.
            Format: `uuid`
            Example: `'bf1a040c-8c58-4bc2-bec2-c5ae7de8bd84'`
        :param deleted: (optional)  An optional boolean parameter. It must be set to `true` when retrieving the block model for the given `bm_id` that has been deleted via the 'Delete a block model' endpoint. By default, or if set to `false`, an attempt to access a deleted block model will result in an error.
            Example: `False`
        :param additional_headers: (optional) Additional headers to send with the request.
        :param request_timeout: (optional) Timeout setting for this request. If one number is provided, it will be the
            total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

        :return: Returns the result object.

        :raise evo.common.exceptions.BadRequestException: If the server responds with HTTP status 400.
        :raise evo.common.exceptions.UnauthorizedException: If the server responds with HTTP status 401.
        :raise evo.common.exceptions.ForbiddenException: If the server responds with HTTP status 403.
        :raise evo.common.exceptions.NotFoundException: If the server responds with HTTP status 404.
        :raise evo.common.exceptions.BaseTypedError: If the server responds with any other HTTP status between
            400 and 599, and the body of the response contains a descriptive `type` parameter.
        :raise evo.common.exceptions.EvoAPIException: If the server responds with any other HTTP status between 400
            and 599, and the body of the response does not contain a `type` parameter.
        :raise evo.common.exceptions.UnknownResponseError: For other HTTP status codes with no corresponding response
            type in `response_types_map`.
        """
        # Prepare the path parameters.
        _path_params = {
            "bm_id": bm_id,
            "workspace_id": workspace_id,
            "org_id": org_id,
        }

        # Prepare the query parameters.
        _query_params = {}
        if deleted is not None:
            _query_params["deleted"] = deleted

        # Prepare the header parameters.
        _header_params = {
            "Accept": "application/json",
        } | get_header_metadata(__name__)
        if additional_headers is not None:
            _header_params.update(additional_headers)

        # Define the collection formats.
        _collection_formats = {}

        _response_types_map = {
            "200": BlockModel,  # noqa: F405
        }

        return await self.connector.call_api(
            method=RequestMethod.GET,
            resource_path="/blockmodel/orgs/{org_id}/workspaces/{workspace_id}/block-models/{bm_id}",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            collection_formats=_collection_formats,
            response_types_map=_response_types_map,
            request_timeout=request_timeout,
        )
