# Code generated by protoc-gen-meshpy. DO NOT EDIT.
# source: meshtrade/wallet/account/v1/service.proto

"""
AccountService gRPC service wrapper with authentication, timeouts, and resource management.

This module provides a high-level gRPC service for the AccountService service that combines
the service interface with resource management capabilities, providing authentication,
timeouts, and proper connection handling.
"""

from collections.abc import Iterator
from datetime import timedelta
from typing import Optional

from meshtrade.common import BaseGRPCClient
from meshtrade.iam.api_user.v1.api_credentials import find_credentials

from .account_pb2 import Account
from meshtrade.common.service_options import ServiceOptions
from .service_pb2 import (
AddSignatoriesToAccountRequest,
AddSignatoriesToAccountResponse,
CreateAccountRequest,
DeregisterTokensFromAccountRequest,
DeregisterTokensFromAccountResponse,
GetAccountByNumberRequest,
GetAccountRequest,
ListAccountsRequest,
ListAccountsResponse,
OpenAccountRequest,
OpenAccountResponse,
RegisterTokensToAccountRequest,
RegisterTokensToAccountResponse,
RemoveSignatoriesFromAccountRequest,
RemoveSignatoriesFromAccountResponse,
SearchAccountsRequest,
SearchAccountsResponse,
UpdateAccountRequest,
)
from .service_pb2_grpc import AccountServiceStub


def _create_accountservice_stub(channel):
    """Factory function to create AccountServiceStub from gRPC channel."""
    return AccountServiceStub(channel)


class AccountService(BaseGRPCClient):
    """AccountService gRPC service with authentication, timeouts, and resource management.

    This service provides a complete implementation of the AccountService with proper authentication, timeout handling, and automatic resource cleanup.

    Full Service documentation: https://meshtrade.github.io/api/docs/api-reference/wallet/account/v1

    Basic service usage with default SDK Configuration:
    ```python
    service = AccountService()

    with service:   # `with` ensures proper clean up of underlying connection after use
        response = service.get_api_user(request)
    ```
        
    With default configuration API credentials are searched for using the standard discovery hierarchy:
    
    1. MESH_API_CREDENTIALS environment variable
    
    2. Default credential file location:
    
    - Linux:   `$XDG_CONFIG_HOME/mesh/credentials.json` or fallback to `$HOME/.config/mesh/credentials.json`
    - macOS:   `$HOME/Library/Application Support/mesh/credentials.json`
    - Windows: `C:\\Users\\<user>\\AppData\\Roaming\\mesh\\credentials.json`
    
    For more information on authentication: https://meshtrade.github.io/api/docs/architecture/authentication

    The service may also be configured with custom options:
    ```python
    from .service_options_meshpy import ServiceOptions
    from datetime import timedelta

    options = ServiceOptions(
        url="api.staging.example.com",
        port=443,
        api_key="your-api-key",
        group="groups/your-group-id",
        timeout=timedelta(seconds=60)
    )

    service = AccountService(options)

    with service: # `with` ensures proper clean up of underlying connection after use
        response = service.get_api_user(request)
    ```

    For more information on service configuration: https://meshtrade.github.io/api/docs/architecture/sdk-configuration
    """

    def __init__(self, options: Optional[ServiceOptions] = None):
        """Construct and initialize the AccountService service.

        Full Service documentation: https://meshtrade.github.io/api/docs/api-reference/wallet/account/v1

        Args:
            options: Optional ServiceOptions for configuring the service.
                    If None, service is constructed with default configuration.
                    With default configuration API credentials are searched for using the standard discovery hierarchy:
                    
                    1. MESH_API_CREDENTIALS environment variable
                    
                    2. Default credential file location:
                    
                    - Linux:   `$XDG_CONFIG_HOME/mesh/credentials.json` or fallback to `$HOME/.config/mesh/credentials.json`
                    - macOS:   `$HOME/Library/Application Support/mesh/credentials.json`
                    - Windows: `C:\\Users\\<user>\\AppData\\Roaming\\mesh\\credentials.json`      

                    For more information on authentication: https://meshtrade.github.io/api/docs/architecture/authentication

                    For more information on service configuration: https://meshtrade.github.io/api/docs/architecture/sdk-configuration            

        Example:
        ```python
        # construct with default configuration
        service = AccountService()

        # construct with custom configuration
        options = ServiceOptions(
            url="api.example.com",
            api_key="your-key",
            group="groups/your-group"
        )
        service = AccountService(options)
        ```
        """
        if options is None:
            options = ServiceOptions()

        # Initialize the base client with all common functionality
        super().__init__(
            service_name="AccountService",
            stub_factory=_create_accountservice_stub,
            find_credentials_func=find_credentials,
            url=options.url,
            port=options.port,
            api_key=options.api_key,
            group=options.group,
            timeout=options.timeout,
            tls=options.tls,
        )

    def create_account(self, request: CreateAccountRequest, timeout: Optional[timedelta] = None) -> Account:
        """CreateAccount method.

        Args:
            request: The CreateAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The CreateAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("CreateAccount", request, timeout)

    def update_account(self, request: UpdateAccountRequest, timeout: Optional[timedelta] = None) -> Account:
        """UpdateAccount method.

        Args:
            request: The UpdateAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The UpdateAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("UpdateAccount", request, timeout)

    def open_account(self, request: OpenAccountRequest, timeout: Optional[timedelta] = None) -> OpenAccountResponse:
        """OpenAccount method.

        Args:
            request: The OpenAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The OpenAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("OpenAccount", request, timeout)

    def add_signatories_to_account(self, request: AddSignatoriesToAccountRequest, timeout: Optional[timedelta] = None) -> AddSignatoriesToAccountResponse:
        """AddSignatoriesToAccount method.

        Args:
            request: The AddSignatoriesToAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The AddSignatoriesToAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("AddSignatoriesToAccount", request, timeout)

    def remove_signatories_from_account(self, request: RemoveSignatoriesFromAccountRequest, timeout: Optional[timedelta] = None) -> RemoveSignatoriesFromAccountResponse:
        """RemoveSignatoriesFromAccount method.

        Args:
            request: The RemoveSignatoriesFromAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The RemoveSignatoriesFromAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("RemoveSignatoriesFromAccount", request, timeout)

    def get_account(self, request: GetAccountRequest, timeout: Optional[timedelta] = None) -> Account:
        """GetAccount method.

        Args:
            request: The GetAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The GetAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("GetAccount", request, timeout)

    def get_account_by_number(self, request: GetAccountByNumberRequest, timeout: Optional[timedelta] = None) -> Account:
        """GetAccountByNumber method.

        Args:
            request: The GetAccountByNumber request message
            timeout: Optional timeout override for this call

        Returns:
            The GetAccountByNumber response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("GetAccountByNumber", request, timeout)

    def list_accounts(self, request: ListAccountsRequest, timeout: Optional[timedelta] = None) -> ListAccountsResponse:
        """ListAccounts method.

        Args:
            request: The ListAccounts request message
            timeout: Optional timeout override for this call

        Returns:
            The ListAccounts response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("ListAccounts", request, timeout)

    def search_accounts(self, request: SearchAccountsRequest, timeout: Optional[timedelta] = None) -> SearchAccountsResponse:
        """SearchAccounts method.

        Args:
            request: The SearchAccounts request message
            timeout: Optional timeout override for this call

        Returns:
            The SearchAccounts response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("SearchAccounts", request, timeout)

    def register_tokens_to_account(self, request: RegisterTokensToAccountRequest, timeout: Optional[timedelta] = None) -> RegisterTokensToAccountResponse:
        """RegisterTokensToAccount method.

        Args:
            request: The RegisterTokensToAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The RegisterTokensToAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("RegisterTokensToAccount", request, timeout)

    def deregister_tokens_from_account(self, request: DeregisterTokensFromAccountRequest, timeout: Optional[timedelta] = None) -> DeregisterTokensFromAccountResponse:
        """DeregisterTokensFromAccount method.

        Args:
            request: The DeregisterTokensFromAccount request message
            timeout: Optional timeout override for this call

        Returns:
            The DeregisterTokensFromAccount response message

        Raises:
            grpc.RpcError: If the gRPC call fails
            ValueError: If authentication credentials are missing
        """
        return self._execute_method("DeregisterTokensFromAccount", request, timeout)


# Create aliases to match expected exports
AccountServiceGRPCClient = AccountService
AccountServiceGRPCClientInterface = AccountService
