import logging
from typing import Any, Optional
from warnings import warn

from pydantic import BaseModel, Field, computed_field

from ipfabric.models.table import Table

logger = logging.getLogger("ipfabric")


class LoadBalancing(BaseModel):
    client: Any = Field(None, exclude=True)
    sn: Optional[str] = None

    @computed_field
    @property
    def virtual_servers(self) -> Table:
        return Table(client=self.client, endpoint="tables/load-balancing/virtual-servers", sn=self.sn)

    @computed_field
    @property
    def virtual_servers_pools(self) -> Table:
        return Table(client=self.client, endpoint="tables/load-balancing/virtual-servers/pools", sn=self.sn)

    @computed_field
    @property
    def virtual_servers_pool_members(self) -> Table:
        return Table(client=self.client, endpoint="tables/load-balancing/virtual-servers/pool-members", sn=self.sn)

    @computed_field
    @property
    def partitions(self) -> Table:
        return Table(client=self.client, endpoint="tables/load-balancing/partitions", sn=self.sn)

    @computed_field
    @property
    def virtual_servers_f5_partitions(self) -> Table:
        # TODO: Remove 7.0
        warn(
            "LoadBalancing.virtual_servers_f5_partitions will be moved to LoadBalancing.partitions in 7.0",
            DeprecationWarning,
            stacklevel=2,
        )
        return Table(client=self.client, endpoint="tables/load-balancing/f5-partitions", sn=self.sn)
