from typing import Any

from ewokscore.model import BaseInputModel
from pydantic import ValidationInfo
from pydantic import field_validator


class FluoInputs(BaseInputModel):

    @field_validator("*", mode="before")
    @classmethod
    def none_to_default(cls, value: Any, info: ValidationInfo) -> Any:
        if value is not None:
            return value

        field = cls.model_fields[info.field_name]

        if field.default is not None:
            return field.default

        if field.default_factory is not None:
            return field.default_factory()

        return value
