"""ASV benchmarks for resource type domain model validation."""

_BASE_CONFIG = {
    "name": "bench/model-type",
    "description": "Benchmark resource type",
    "resource_kind": "physical",
    "sandbox_strategy": "git_worktree",
    "built_in": False,
    "user_addable": True,
    "cli_args": [
        {
            "name": "path",
            "type": "path",
            "required": True,
            "description": "Path",
        },
        {
            "name": "branch",
            "type": "string",
            "required": False,
            "description": "Branch",
        },
    ],
    "parent_types": [],
    "child_types": ["fs-directory"],
    "capabilities": {
        "read": True,
        "write": True,
        "sandbox": True,
        "checkpoint": False,
    },
}


class TimeFromConfig:
    """Benchmark ResourceTypeSpec.from_config() throughput."""

    def setup(self):
        from cleveragents.domain.models.core.resource_type import (
            ResourceTypeSpec,
        )

        self.spec_cls = ResourceTypeSpec
        self.config = dict(_BASE_CONFIG)

    def time_from_config(self):
        self.spec_cls.from_config(self.config)

    def time_from_config_10x(self):
        for _ in range(10):
            self.spec_cls.from_config(self.config)


class TimeAsCliDict:
    """Benchmark as_cli_dict() rendering."""

    def setup(self):
        from cleveragents.domain.models.core.resource_type import (
            ResourceTypeSpec,
        )

        self.spec = ResourceTypeSpec.from_config(dict(_BASE_CONFIG))

    def time_as_cli_dict(self):
        self.spec.as_cli_dict()

    def time_as_cli_dict_10x(self):
        for _ in range(10):
            self.spec.as_cli_dict()


class TimeNameValidation:
    """Benchmark name validation for built-in vs custom types."""

    def setup(self):
        from cleveragents.domain.models.core.resource_type import (
            ResourceTypeSpec,
        )

        self.spec_cls = ResourceTypeSpec
        self.builtin_config = {
            **_BASE_CONFIG,
            "name": "git-checkout",
            "built_in": True,
        }
        self.custom_config = dict(_BASE_CONFIG)

    def time_builtin_validation(self):
        self.spec_cls.from_config(self.builtin_config)

    def time_custom_validation(self):
        self.spec_cls.from_config(self.custom_config)
