from pydantic import BaseModel
from typing import Optional, Dict, Any

from app.components.filter.domain.value_objects.filter import FiltersValueObject

class InputFilter(BaseModel):
    trashed: int = 0
    paginate: int = 0
    page: int = 1
    rows: int = 25
    filters: FiltersValueObject = FiltersValueObject()

    @classmethod
    def from_request_body(cls, body: Optional[Dict[str, Any]] = None) -> "InputFilter":
        if body is None:
            body = {}

        return cls(
            trashed= 1 if body.get("trashed", 0) != 0 else body.get("trashed", 0),
            paginate= 1 if body.get("paginate", 0) != 0 else body.get("paginate", 0),
            page= 1 if body.get("page", 0) == 0 else body.get("page", 0),
            rows=body.get("rows", 25),
            filters=FiltersValueObject.from_raw(body.get("filters"))
        )