from __future__ import annotations

"""
Copyright (C) 2025 Luciano Guerche

This file is part of rabbitmq-mcp-server.

rabbitmq-mcp-server is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

rabbitmq-mcp-server is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with rabbitmq-mcp-server. If not, see <https://www.gnu.org/licenses/>.
"""

"""Pool metrics schema for HTTP connection pool health tracking (Story 2.6)."""

from pydantic import BaseModel, field_validator


class PoolMetrics(BaseModel):
    """Connection pool health metrics model (Story 2.6 AC #5, #11).

    Tracks comprehensive pool health including connection counts,
    request statistics, and health score for alerting.
    """

    active_connections: int
    pool_size: int
    wait_time: float | None = None
    total_requests: int = 0
    successful_requests: int = 0
    failed_requests: int = 0
    evictions_last_hour: int = 0
    pool_exhaustion_count: int = 0
    health_score: float = 1.0

    @field_validator("health_score")
    @classmethod
    def validate_health_score(cls, v: float) -> float:
        """Validate health score is in valid range 0.0-1.0 (AC #11)."""
        if not 0.0 <= v <= 1.0:
            raise ValueError(f"Health score must be between 0.0 and 1.0, got {v}")
        return v

    @field_validator(
        "active_connections",
        "pool_size",
        "total_requests",
        "successful_requests",
        "failed_requests",
        "evictions_last_hour",
        "pool_exhaustion_count",
    )
    @classmethod
    def validate_non_negative(cls, v: int) -> int:
        """Validate integer metrics are non-negative."""
        if v < 0:
            raise ValueError(f"Value must be non-negative, got {v}")
        return v


__all__ = ["PoolMetrics"]
