from app.core.constants import SUPPORTED_SCHEMA_VERSION
from app.core.exceptions import AppError
from app.schemas.changeset import ChangeItem, ChangeSetPayload
from app.schemas.common import ModuleName


class ChangeSetValidator:
    def validate(self, task_id: str, changeset: list[ChangeItem]) -> list[ChangeItem]:
        payload = ChangeSetPayload(
            schema_version=SUPPORTED_SCHEMA_VERSION,
            task_id=task_id,
            changeset=changeset,
        )
        if payload.schema_version != SUPPORTED_SCHEMA_VERSION:
            raise AppError(
                "unsupported_schema",
                f"Unsupported schema version: {payload.schema_version}",
                ModuleName.AGENT,
            )
        return payload.changeset
