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

from .core import InnerClient
from typing import List
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .items_files import ItemsFiles
from .types import (
    Item,
    ItemCreateParams,
    ItemListFilter,
    ItemOverview,
    ItemsDeleteAllResponse,
    ItemsGetAllResponse,
    ItemsUpdateAllResponse,
)


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

    def __init__(self, inner_client: InnerClient):
        self.inner_client = inner_client
        self.shares = ItemsShares(inner_client)
        self.files = ItemsFiles(inner_client)

    async def create(self, params: ItemCreateParams) -> Item:
        """
        Create a new item.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsCreate",
                        "parameters": {"params": params.model_dump(by_alias=True)},
                    },
                }
            }
        )

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

    async def create_all(
        self, vault_id: str, params: List[ItemCreateParams]
    ) -> ItemsUpdateAllResponse:
        """
        Create items in batch, within a single vault.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsCreateAll",
                        "parameters": {
                            "vault_id": vault_id,
                            "params": [o.model_dump(by_alias=True) for o in params],
                        },
                    },
                }
            }
        )

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

    async def get(self, vault_id: str, item_id: str) -> Item:
        """
        Get an item by vault and item ID.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsGet",
                        "parameters": {"vault_id": vault_id, "item_id": item_id},
                    },
                }
            }
        )

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

    async def get_all(self, vault_id: str, item_ids: List[str]) -> ItemsGetAllResponse:
        """
        Get items by vault and their item IDs.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsGetAll",
                        "parameters": {"vault_id": vault_id, "item_ids": item_ids},
                    },
                }
            }
        )

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

    async def put(self, item: Item) -> Item:
        """
        Update an existing item.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsPut",
                        "parameters": {"item": item.model_dump(by_alias=True)},
                    },
                }
            }
        )

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

    async def delete(self, vault_id: str, item_id: str) -> None:
        """
        Delete an item.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsDelete",
                        "parameters": {"vault_id": vault_id, "item_id": item_id},
                    },
                }
            }
        )

        return None

    async def delete_all(
        self, vault_id: str, item_ids: List[str]
    ) -> ItemsDeleteAllResponse:
        """
        Delete items in batch, within a single vault.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsDeleteAll",
                        "parameters": {"vault_id": vault_id, "item_ids": item_ids},
                    },
                }
            }
        )

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

    async def archive(self, vault_id: str, item_id: str) -> None:
        """
        Archive an item.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsArchive",
                        "parameters": {"vault_id": vault_id, "item_id": item_id},
                    },
                }
            }
        )

        return None

    async def list(self, vault_id: str, *filters: ItemListFilter) -> List[ItemOverview]:
        """
        List items based on filters.
        """
        response = await self.inner_client.invoke(
            {
                "invocation": {
                    "clientId": self.inner_client.client_id,
                    "parameters": {
                        "name": "ItemsList",
                        "parameters": {
                            "vault_id": vault_id,
                            "filters": [o.model_dump(by_alias=True) for o in filters],
                        },
                    },
                }
            }
        )

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