# @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 (
    ChangeSchedule,
    ChangeScheduleCreate,
    ChangeScheduleCreateModel,
    ChangeScheduleFilter,
    ChangeScheduleFilterModel,
    ChangeScheduleUpdate,
    ChangeScheduleUpdateModel,
)


class ChangeScheduleEndpoint(Endpoint):
    BASE_PATH: Final[str] = "workflow/v1/change-schedule"

    def list(self, **filters: Unpack[ChangeScheduleFilter]) -> Iterator[ChangeSchedule]:
        results = self._list(self.BASE_PATH, ChangeScheduleFilterModel, filters)
        return map_sync(ChangeSchedule.parse_api, results)

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

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

    def create(self, **payload: Unpack[ChangeScheduleCreate]) -> ChangeSchedule:
        result = self._create(self.BASE_PATH, ChangeScheduleCreateModel, payload)
        return ChangeSchedule.parse_api(result)

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

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