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

from .core import InnerClient
from typing import List
from pydantic import TypeAdapter
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient


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

    async def get_account_policy(
        self, vault_id: str, item_id: str
    ) -> ItemShareAccountPolicy:
        """
        Get the item sharing policy of your account.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsSharesGetAccountPolicy",
                        "parameters": {"vault_id": vault_id, "item_id": item_id},
                    },
                }
            }
        )

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

    async def validate_recipients(
        self, policy: ItemShareAccountPolicy, recipients: List[str]
    ) -> List[ValidRecipient]:
        """
        Validate the recipients of an item sharing link.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsSharesValidateRecipients",
                        "parameters": {
                            "policy": policy.model_dump(by_alias=True),
                            "recipients": recipients,
                        },
                    },
                }
            }
        )

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

    async def create(
        self, item: Item, policy: ItemShareAccountPolicy, params: ItemShareParams
    ) -> str:
        """
        Create a new item sharing link.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsSharesCreate",
                        "parameters": {
                            "item": item.model_dump(by_alias=True),
                            "policy": policy.model_dump(by_alias=True),
                            "params": params.model_dump(by_alias=True),
                        },
                    },
                }
            }
        )

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