# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import InnerClient
from typing import List, Optional
from pydantic import TypeAdapter
from .types import (
    GroupAccess,
    GroupVaultAccess,
    Vault,
    VaultCreateParams,
    VaultGetParams,
    VaultListParams,
    VaultOverview,
    VaultUpdateParams,
)


class Vaults:
    """
    The Vaults API holds all the operations the SDK client can perform on 1Password vaults.
    """

    def __init__(self, inner_client: InnerClient):
        self.inner_client = inner_client

    async def create(self, params: VaultCreateParams) -> Vault:
        """
        Create a new user vault.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsCreate",
                        "parameters": {"params": params.model_dump(by_alias=True)},
                    },
                }
            }
        )

        response = TypeAdapter(Vault).validate_json(response)
        return response

    async def list(
        self, params: Optional[VaultListParams] = None
    ) -> List[VaultOverview]:
        """
        List information about vaults that's configurable based on some input parameters.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsList",
                        "parameters": {
                            "params": (
                                params.model_dump(by_alias=True) if params else None
                            )
                        },
                    },
                }
            }
        )

        response = TypeAdapter(List[VaultOverview]).validate_json(response)
        return response

    async def get_overview(self, vault_id: str) -> VaultOverview:
        """
        Get an overview of a vault by its ID.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsGetOverview",
                        "parameters": {"vault_id": vault_id},
                    },
                }
            }
        )

        response = TypeAdapter(VaultOverview).validate_json(response)
        return response

    async def get(self, vault_id: str, vault_params: VaultGetParams) -> Vault:
        """
        Get detailed vault information by vault ID and parameters.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsGet",
                        "parameters": {
                            "vault_id": vault_id,
                            "vault_params": vault_params.model_dump(by_alias=True),
                        },
                    },
                }
            }
        )

        response = TypeAdapter(Vault).validate_json(response)
        return response

    async def update(self, vault_id: str, params: VaultUpdateParams) -> Vault:
        """
        Update a vault
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsUpdate",
                        "parameters": {
                            "vault_id": vault_id,
                            "params": params.model_dump(by_alias=True),
                        },
                    },
                }
            }
        )

        response = TypeAdapter(Vault).validate_json(response)
        return response

    async def delete(self, vault_id: str) -> None:
        """
        Delete a vault by its ID.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsDelete",
                        "parameters": {"vault_id": vault_id},
                    },
                }
            }
        )

        return None

    async def grant_group_permissions(
        self, vault_id: str, group_permissions_list: List[GroupAccess]
    ) -> None:
        """
        Grant group permissions to a vault.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsGrantGroupPermissions",
                        "parameters": {
                            "vault_id": vault_id,
                            "group_permissions_list": [
                                o.model_dump(by_alias=True)
                                for o in group_permissions_list
                            ],
                        },
                    },
                }
            }
        )

        return None

    async def update_group_permissions(
        self, group_permissions_list: List[GroupVaultAccess]
    ) -> None:
        """
        Update group permissions for vaults.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsUpdateGroupPermissions",
                        "parameters": {
                            "group_permissions_list": [
                                o.model_dump(by_alias=True)
                                for o in group_permissions_list
                            ]
                        },
                    },
                }
            }
        )

        return None

    async def revoke_group_permissions(self, vault_id: str, group_id: str) -> None:
        """
        Revoke group permissions from a vault.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "VaultsRevokeGroupPermissions",
                        "parameters": {"vault_id": vault_id, "group_id": group_id},
                    },
                }
            }
        )

        return None
