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

from .basesdk import BaseSDK
from ascend_sdk import utils
from ascend_sdk._hooks import HookContext
from ascend_sdk.models import components, errors, operations
from ascend_sdk.types import OptionalNullable, UNSET
from typing import Any, Optional, Union


class Retirements(BaseSDK):
    def list_contribution_summaries(
        self,
        *,
        account_id: str,
        page_size: Optional[int] = None,
        page_token: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsListContributionSummariesResponse:
        r"""List Contribution Summaries

        Lists the aggregated retirement contribution summaries by tax year

        :param account_id: The account id.
        :param page_size: Number of contribution summaries to get (partitioned by tax year) Default = 2 (current year and prior year), maximum = 10
        :param page_token: When paginating, this is used to retrieve a specific page from the overall response
        :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
        """
        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

        request = operations.RetirementConstraintsListContributionSummariesRequest(
            account_id=account_id,
            page_size=page_size,
            page_token=page_token,
        )

        req = self.build_request(
            method="GET",
            path="/transfers/v1/accounts/{account_id}/contributionSummaries",
            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",
            security=self.sdk_configuration.security,
            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(
                operation_id="RetirementConstraints_ListContributionSummaries",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.RetirementConstraintsListContributionSummariesResponse(
                list_contribution_summaries_response=utils.unmarshal_json(
                    http_res.text,
                    Optional[components.ListContributionSummariesResponse],
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.RetirementConstraintsListContributionSummariesResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def list_contribution_summaries_async(
        self,
        *,
        account_id: str,
        page_size: Optional[int] = None,
        page_token: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsListContributionSummariesResponse:
        r"""List Contribution Summaries

        Lists the aggregated retirement contribution summaries by tax year

        :param account_id: The account id.
        :param page_size: Number of contribution summaries to get (partitioned by tax year) Default = 2 (current year and prior year), maximum = 10
        :param page_token: When paginating, this is used to retrieve a specific page from the overall response
        :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
        """
        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

        request = operations.RetirementConstraintsListContributionSummariesRequest(
            account_id=account_id,
            page_size=page_size,
            page_token=page_token,
        )

        req = self.build_request_async(
            method="GET",
            path="/transfers/v1/accounts/{account_id}/contributionSummaries",
            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",
            security=self.sdk_configuration.security,
            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(
                operation_id="RetirementConstraints_ListContributionSummaries",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return operations.RetirementConstraintsListContributionSummariesResponse(
                list_contribution_summaries_response=utils.unmarshal_json(
                    http_res.text,
                    Optional[components.ListContributionSummariesResponse],
                ),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return operations.RetirementConstraintsListContributionSummariesResponse(
                status=utils.unmarshal_json(http_res.text, Optional[components.Status]),
                http_meta=components.HTTPMetadata(request=req, response=http_res),
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    def retrieve_contribution_constraints(
        self,
        *,
        account_id: str,
        retrieve_contribution_constraints_request_create: Union[
            components.RetrieveContributionConstraintsRequestCreate,
            components.RetrieveContributionConstraintsRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsRetrieveContributionConstraintsResponse:
        r"""Retrieve Contribution Constraints

        Retrieves retirement contribution constraints for an account

        :param account_id: The account id.
        :param retrieve_contribution_constraints_request_create:
        :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
        """
        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

        request = operations.RetirementConstraintsRetrieveContributionConstraintsRequest(
            account_id=account_id,
            retrieve_contribution_constraints_request_create=utils.get_pydantic_model(
                retrieve_contribution_constraints_request_create,
                components.RetrieveContributionConstraintsRequestCreate,
            ),
        )

        req = self.build_request(
            method="POST",
            path="/transfers/v1/accounts/{account_id}:retrieveContributionConstraints",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_contribution_constraints_request_create,
                False,
                False,
                "json",
                components.RetrieveContributionConstraintsRequestCreate,
            ),
            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(
                operation_id="RetirementConstraints_RetrieveContributionConstraints",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveContributionConstraintsResponse(
                    contribution_constraints=utils.unmarshal_json(
                        http_res.text, Optional[components.ContributionConstraints]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveContributionConstraintsResponse(
                    status=utils.unmarshal_json(
                        http_res.text, Optional[components.Status]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def retrieve_contribution_constraints_async(
        self,
        *,
        account_id: str,
        retrieve_contribution_constraints_request_create: Union[
            components.RetrieveContributionConstraintsRequestCreate,
            components.RetrieveContributionConstraintsRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsRetrieveContributionConstraintsResponse:
        r"""Retrieve Contribution Constraints

        Retrieves retirement contribution constraints for an account

        :param account_id: The account id.
        :param retrieve_contribution_constraints_request_create:
        :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
        """
        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

        request = operations.RetirementConstraintsRetrieveContributionConstraintsRequest(
            account_id=account_id,
            retrieve_contribution_constraints_request_create=utils.get_pydantic_model(
                retrieve_contribution_constraints_request_create,
                components.RetrieveContributionConstraintsRequestCreate,
            ),
        )

        req = self.build_request_async(
            method="POST",
            path="/transfers/v1/accounts/{account_id}:retrieveContributionConstraints",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_contribution_constraints_request_create,
                False,
                False,
                "json",
                components.RetrieveContributionConstraintsRequestCreate,
            ),
            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(
                operation_id="RetirementConstraints_RetrieveContributionConstraints",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveContributionConstraintsResponse(
                    contribution_constraints=utils.unmarshal_json(
                        http_res.text, Optional[components.ContributionConstraints]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveContributionConstraintsResponse(
                    status=utils.unmarshal_json(
                        http_res.text, Optional[components.Status]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    def retrieve_distribution_constraints(
        self,
        *,
        account_id: str,
        retrieve_distribution_constraints_request_create: Union[
            components.RetrieveDistributionConstraintsRequestCreate,
            components.RetrieveDistributionConstraintsRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsRetrieveDistributionConstraintsResponse:
        r"""Retrieve Distribution Constraints

        Retrieves retirement distribution constraints for an account

        :param account_id: The account id.
        :param retrieve_distribution_constraints_request_create:
        :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
        """
        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

        request = operations.RetirementConstraintsRetrieveDistributionConstraintsRequest(
            account_id=account_id,
            retrieve_distribution_constraints_request_create=utils.get_pydantic_model(
                retrieve_distribution_constraints_request_create,
                components.RetrieveDistributionConstraintsRequestCreate,
            ),
        )

        req = self.build_request(
            method="POST",
            path="/transfers/v1/accounts/{account_id}:retrieveDistributionConstraints",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_distribution_constraints_request_create,
                False,
                False,
                "json",
                components.RetrieveDistributionConstraintsRequestCreate,
            ),
            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(
                operation_id="RetirementConstraints_RetrieveDistributionConstraints",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveDistributionConstraintsResponse(
                    distribution_constraints=utils.unmarshal_json(
                        http_res.text, Optional[components.DistributionConstraints]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveDistributionConstraintsResponse(
                    status=utils.unmarshal_json(
                        http_res.text, Optional[components.Status]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )

    async def retrieve_distribution_constraints_async(
        self,
        *,
        account_id: str,
        retrieve_distribution_constraints_request_create: Union[
            components.RetrieveDistributionConstraintsRequestCreate,
            components.RetrieveDistributionConstraintsRequestCreateTypedDict,
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
    ) -> operations.RetirementConstraintsRetrieveDistributionConstraintsResponse:
        r"""Retrieve Distribution Constraints

        Retrieves retirement distribution constraints for an account

        :param account_id: The account id.
        :param retrieve_distribution_constraints_request_create:
        :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
        """
        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

        request = operations.RetirementConstraintsRetrieveDistributionConstraintsRequest(
            account_id=account_id,
            retrieve_distribution_constraints_request_create=utils.get_pydantic_model(
                retrieve_distribution_constraints_request_create,
                components.RetrieveDistributionConstraintsRequestCreate,
            ),
        )

        req = self.build_request_async(
            method="POST",
            path="/transfers/v1/accounts/{account_id}:retrieveDistributionConstraints",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request.retrieve_distribution_constraints_request_create,
                False,
                False,
                "json",
                components.RetrieveDistributionConstraintsRequestCreate,
            ),
            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(
                operation_id="RetirementConstraints_RetrieveDistributionConstraints",
                oauth2_scopes=[],
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "403", "4XX", "5XX"],
            retry_config=retry_config,
        )

        data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveDistributionConstraintsResponse(
                    distribution_constraints=utils.unmarshal_json(
                        http_res.text, Optional[components.DistributionConstraints]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )
        if utils.match_response(http_res, ["400", "403"], "application/json"):
            data = utils.unmarshal_json(http_res.text, errors.StatusData)
            raise errors.Status(data=data)
        if utils.match_response(http_res, ["4XX", "5XX"], "*"):
            raise errors.SDKError(
                "API error occurred", http_res.status_code, http_res.text, http_res
            )
        if utils.match_response(http_res, "default", "application/json"):
            return (
                operations.RetirementConstraintsRetrieveDistributionConstraintsResponse(
                    status=utils.unmarshal_json(
                        http_res.text, Optional[components.Status]
                    ),
                    http_meta=components.HTTPMetadata(request=req, response=http_res),
                )
            )

        content_type = http_res.headers.get("Content-Type")
        raise errors.SDKError(
            f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
            http_res.status_code,
            http_res.text,
            http_res,
        )
