import uuid
from dataclasses import dataclass
from typing import override

from ai.backend.manager.actions.action import BaseActionResult
from ai.backend.manager.actions.types import ActionOperationType
from ai.backend.manager.data.model_serving.types import EndpointData
from ai.backend.manager.models.endpoint import EndpointRow
from ai.backend.manager.repositories.base.updater import Updater
from ai.backend.manager.services.model_serving.actions.base import ModelServiceAction


@dataclass
class ModifyEndpointAction(ModelServiceAction):
    endpoint_id: uuid.UUID
    updater: Updater[EndpointRow]

    @override
    def entity_id(self) -> str | None:
        return None

    @override
    @classmethod
    def operation_type(cls) -> ActionOperationType:
        return ActionOperationType.UPDATE


@dataclass
class ModifyEndpointActionResult(BaseActionResult):
    success: bool
    data: EndpointData | None

    @override
    def entity_id(self) -> str | None:
        return str(self.data.id) if self.data is not None else None
