# @generated
# This file was automatically generated by the ncae-sdk code generator.
# DO NOT EDIT MANUALLY, ANY CHANGES WILL BE OVERWRITTEN.

from collections.abc import Iterator
from typing import Final, Optional

from typing_extensions import Unpack

from ncae_sdk._resource import ResourceId
from ncae_sdk._sync.endpoint import Endpoint
from ncae_sdk._util import map_sync
from ncae_sdk.resources._schema import (
    Tag,
    TagCreate,
    TagCreateModel,
    TagFilter,
    TagFilterModel,
    TagUpdate,
    TagUpdateModel,
)


class TagEndpoint(Endpoint):
    BASE_PATH: Final[str] = "tag/v1/tag"

    def list(self, **filters: Unpack[TagFilter]) -> Iterator[Tag]:
        results = self._list(self.BASE_PATH, TagFilterModel, filters)
        return map_sync(Tag.parse_api, results)

    def find(self, **filters: Unpack[TagFilter]) -> Optional[Tag]:
        result = self._get_by_filters(self.BASE_PATH, TagFilterModel, filters)
        return Tag.parse_api(result) if result else None

    def get(self, rid: ResourceId) -> Optional[Tag]:
        result = self._get_by_id(self.BASE_PATH, rid)
        return Tag.parse_api(result) if result else None

    def create(self, **payload: Unpack[TagCreate]) -> Tag:
        result = self._create(self.BASE_PATH, TagCreateModel, payload)
        return Tag.parse_api(result)

    def update(self, rid: ResourceId, /, **payload: Unpack[TagUpdate]) -> Tag:
        result = self._update(self.BASE_PATH, rid, TagUpdateModel, payload)
        return Tag.parse_api(result)

    def delete(self, rid: ResourceId) -> bool:
        return self._delete(self.BASE_PATH, rid)
