"""OGImage preset management mixins."""

from __future__ import annotations

from ..._api.generated.ogimage.ogimage__api__ogimage.models import (
    OGImagePreset,
    OGImagePresetRequest,
    PatchedOGImagePresetRequest,
    PaginatedOGImagePresetList,
)
from ...exceptions import api_error_handler, async_api_error_handler


class _PresetsMixin:
    """Sync preset CRUD methods."""

    @api_error_handler
    def list_presets(
        self,
        *,
        ordering: str | None = None,
        search: str | None = None,
        page: int | None = None,
        page_size: int | None = None,
    ) -> PaginatedOGImagePresetList:
        """List available OG image presets."""
        return self._api.presets_list(
            ordering=ordering, search=search, page=page, page_size=page_size,
        )

    @api_error_handler
    def get_preset(self, preset_id: int | str) -> OGImagePreset:
        """Get a preset by ID."""
        return self._api.presets_retrieve(str(preset_id))

    @api_error_handler
    def create_preset(self, data: OGImagePresetRequest) -> OGImagePreset:
        """Create a new preset."""
        return self._api.presets_create(data)

    @api_error_handler
    def update_preset(self, preset_id: int | str, data: OGImagePresetRequest) -> OGImagePreset:
        """Update a preset (full replace)."""
        return self._api.presets_update(str(preset_id), data)

    @api_error_handler
    def patch_preset(self, preset_id: int | str, data: PatchedOGImagePresetRequest) -> OGImagePreset:
        """Partially update a preset."""
        return self._api.presets_partial_update(str(preset_id), data)

    @api_error_handler
    def delete_preset(self, preset_id: int | str) -> None:
        """Delete a preset."""
        return self._api.presets_destroy(str(preset_id))


class _AsyncPresetsMixin:
    """Async preset CRUD methods."""

    @async_api_error_handler
    async def list_presets(
        self,
        *,
        ordering: str | None = None,
        search: str | None = None,
        page: int | None = None,
        page_size: int | None = None,
    ) -> PaginatedOGImagePresetList:
        """List available OG image presets."""
        return await self._api.presets_list(
            ordering=ordering, search=search, page=page, page_size=page_size,
        )

    @async_api_error_handler
    async def get_preset(self, preset_id: int | str) -> OGImagePreset:
        """Get a preset by ID."""
        return await self._api.presets_retrieve(str(preset_id))

    @async_api_error_handler
    async def create_preset(self, data: OGImagePresetRequest) -> OGImagePreset:
        """Create a new preset."""
        return await self._api.presets_create(data)

    @async_api_error_handler
    async def update_preset(self, preset_id: int | str, data: OGImagePresetRequest) -> OGImagePreset:
        """Update a preset (full replace)."""
        return await self._api.presets_update(str(preset_id), data)

    @async_api_error_handler
    async def patch_preset(self, preset_id: int | str, data: PatchedOGImagePresetRequest) -> OGImagePreset:
        """Partially update a preset."""
        return await self._api.presets_partial_update(str(preset_id), data)

    @async_api_error_handler
    async def delete_preset(self, preset_id: int | str) -> None:
        """Delete a preset."""
        return await self._api.presets_destroy(str(preset_id))
