# @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 (
    ExtApiPhase,
    ExtApiPhaseCreate,
    ExtApiPhaseCreateModel,
    ExtApiPhaseFilter,
    ExtApiPhaseFilterModel,
    ExtApiPhaseUpdate,
    ExtApiPhaseUpdateModel,
)


class ExtApiPhaseEndpoint(Endpoint):
    BASE_PATH: Final[str] = "automation/v1/phase/ext-api-phase"

    def list(self, **filters: Unpack[ExtApiPhaseFilter]) -> Iterator[ExtApiPhase]:
        results = self._list(self.BASE_PATH, ExtApiPhaseFilterModel, filters)
        return map_sync(ExtApiPhase.parse_api, results)

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

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

    def create(self, **payload: Unpack[ExtApiPhaseCreate]) -> ExtApiPhase:
        result = self._create(self.BASE_PATH, ExtApiPhaseCreateModel, payload)
        return ExtApiPhase.parse_api(result)

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

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