"""ASV benchmarks for resource type YAML schema validation."""

_VALID_YAML = """
name: bench/perf-type
description: Benchmark resource type
resource_kind: physical
sandbox_strategy: git_worktree
user_addable: true
cli_args:
  - name: path
    type: path
    required: true
    description: Path to resource
  - name: branch
    type: string
    required: false
    description: Branch name
parent_types: []
child_types:
  - fs-directory
capabilities:
  read: true
  write: true
  sandbox: true
  checkpoint: false
"""


class TimeSchemaValidation:
    """Benchmark resource type schema YAML validation throughput."""

    def setup(self):
        from cleveragents.resource.schema import ResourceTypeConfigSchema

        self.schema_cls = ResourceTypeConfigSchema
        self.yaml_string = _VALID_YAML

    def time_from_yaml(self):
        self.schema_cls.from_yaml(self.yaml_string)

    def time_from_yaml_10x(self):
        for _ in range(10):
            self.schema_cls.from_yaml(self.yaml_string)


class TimeSchemaEnvInterpolation:
    """Benchmark env var interpolation in schema loading."""

    def setup(self):
        import os

        from cleveragents.resource.schema import ResourceTypeConfigSchema

        os.environ["BENCH_HANDLER"] = "bench.handler:Handler"
        self.schema_cls = ResourceTypeConfigSchema
        self.yaml_string = """
name: bench/env-type
resource_kind: physical
sandbox_strategy: none
handler: ${BENCH_HANDLER}
"""

    def time_env_interpolation(self):
        self.schema_cls.from_yaml(self.yaml_string)
