from typing import Annotated

from pydantic import Field, StrictFloat, StrictInt, StrictStr, validate_call

from src.client.generated.api.test_case_custom_field_controller_api import TestCaseCustomFieldControllerApi
from src.client.generated.api_client import ApiClient, RequestSerialized
from src.client.generated.models.custom_field_project_with_values_dto import CustomFieldProjectWithValuesDto
from src.client.generated.models.custom_field_value_with_cf_dto import CustomFieldValueWithCfDto


class TestCaseCustomFieldV2ControllerApi(TestCaseCustomFieldControllerApi):
    """NOTE: This class a manual override for the auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    You are allowed to edit the class manually.
    """

    def __init__(self, api_client: ApiClient | None = None) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client
        super().__init__(api_client=api_client)

    @validate_call
    async def get_custom_fields_with_values3(
        self,
        test_case_id: StrictInt,
        project_id: StrictInt,
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, object] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, object] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> list[CustomFieldProjectWithValuesDto]:
        """Find custom fields with values for test case


        :param test_case_id: (required)
        :type test_case_id: int
        :param project_id: (required)
        :type project_id: int
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """

        _param = self._get_custom_fields_with_values3_serialize(
            test_case_id=test_case_id,
            project_id=project_id,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
            _query_params=[("v2", str(True))],
        )

        _response_types_map: dict[str, str | None] = {
            "200": "List[CustomFieldProjectWithValuesDto]",
        }
        response_data = await self.api_client.call_api(*_param, _request_timeout=_request_timeout)
        await response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data

    def _get_custom_fields_with_values3_serialize(
        self,
        test_case_id,
        project_id,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
        _query_params: list[tuple[str, str]] | None = None,
    ) -> RequestSerialized:
        if _query_params is None:
            _query_params = []
        _host = None

        _collection_formats: dict[str, str] = {}

        _path_params: dict[str, str] = {}
        _header_params: dict[str, str | None] = _headers or {}
        _form_params: list[tuple[str, str]] = []
        _files: dict[str, str | bytes | list[str] | list[bytes] | list[tuple[str, bytes]]] = {}
        _body_params: bytes | None = None

        # process the path parameters
        if test_case_id is not None:
            _path_params["testCaseId"] = test_case_id
        # process the query parameters
        if project_id is not None:
            _query_params.append(("projectId", project_id))

        # set the HTTP header `Accept`
        if "Accept" not in _header_params:
            _header_params["Accept"] = self.api_client.select_header_accept(["*/*"])

        # authentication setting
        _auth_settings: list[str] = []

        return self.api_client.param_serialize(
            method="GET",
            resource_path="/api/testcase/{testCaseId}/cfv",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth,
        )

    @validate_call
    async def update_cfvs_of_test_case(
        self,
        test_case_id: StrictInt,
        custom_field_with_values_dto: list[CustomFieldValueWithCfDto],
        _request_timeout: None
        | Annotated[StrictFloat, Field(gt=0)]
        | tuple[Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]] = None,
        _request_auth: dict[StrictStr, object] | None = None,
        _content_type: StrictStr | None = None,
        _headers: dict[StrictStr, object] | None = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> None:
        """Update custom field values of test case


        :param test_case_id: (required)
        :type test_case_id: int
        :param custom_field_with_values_dto: (required)
        :type custom_field_with_values_dto: List[CustomFieldWithValuesDto]
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :type _request_timeout: int, tuple(int, int), optional
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the
                              authentication in the spec for a single request.
        :type _request_auth: dict, optional
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """

        _param = self._update_cfvs_of_test_case_serialize(
            test_case_id=test_case_id,
            custom_field_with_values_dto=custom_field_with_values_dto,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index,
        )

        _response_types_map: dict[str, str | None] = {
            "200": None,
        }
        response_data = await self.api_client.call_api(*_param, _request_timeout=_request_timeout)
        await response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data

    def _update_cfvs_of_test_case_serialize(
        self,
        test_case_id,
        custom_field_with_values_dto,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:
        _host = None

        _collection_formats: dict[str, str] = {
            "CustomFieldValueWithCfDto": "",
        }

        _path_params: dict[str, str] = {}
        _query_params: list[tuple[str, str]] = []
        _header_params: dict[str, str | None] = _headers or {}
        _form_params: list[tuple[str, str]] = []
        _files: dict[str, str | bytes | list[str] | list[bytes] | list[tuple[str, bytes]]] = {}
        _body_params: bytes | None = None

        # process the path parameters
        if test_case_id is not None:
            _path_params["testCaseId"] = test_case_id
        # process the query parameters
        # process the header parameters
        # process the form parameters
        # process the body parameter
        if custom_field_with_values_dto is not None:
            _body_params = custom_field_with_values_dto

        # set the HTTP header `Content-Type`
        if _content_type:
            _header_params["Content-Type"] = _content_type
        else:
            _default_content_type = self.api_client.select_header_content_type(["application/json"])
            if _default_content_type is not None:
                _header_params["Content-Type"] = _default_content_type

        # authentication setting
        _auth_settings: list[str] = []

        return self.api_client.param_serialize(
            method="POST",
            resource_path="/api/testcase/{testCaseId}/cfv",
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth,
        )
