"""Upgrade Policy Optimizer - A library for solving finite MDPs.

This library provides tools for solving Markov Decision Processes (MDPs)
using value iteration to find optimal policies that minimize expected cost.

Main components:
- MDP: Core data structure for defining MDPs
- solve_mdp_value_iteration: Solver function using Bellman optimality
- MDPResult: Result container with value function, policy, and Q-values
- validate_mdp: Validation utilities for MDP structures
- solve_from_json: High-level JSON-based solver
- solve_from_dict: High-level dictionary-based solver

Example (Programmatic):
    >>> from upo import MDP, solve_mdp_value_iteration
    >>> mdp = MDP.from_dict(
    ...     states=["start", "mid", "goal"],
    ...     terminal_states=["goal"],
    ...     transitions_dict={
    ...         "start": {"try": {"mid": 0.7, "start": 0.3}},
    ...         "mid": {"try": {"goal": 1.0}},
    ...     },
    ...     costs_dict={
    ...         "start": {"try": 1.0},
    ...         "mid": {"try": 1.0},
    ...     }
    ... )
    >>> result = solve_mdp_value_iteration(mdp)
    >>> print(result.get_value("start"))
    >>> print(result.get_policy("start"))

Example (JSON-based):
    >>> from upo import solve_from_json
    >>> result = solve_from_json("my_problem.json")
    >>> print(result.get_value("start"))
"""

from importlib.metadata import PackageNotFoundError, version

try:
    # Get version from installed package metadata (setuptools_scm embeds it)
    __version__ = version("upgrade-policy-optimizer")
except PackageNotFoundError:
    # Fallback for development installs: try to read from _version.py generated by setuptools_scm
    try:
        from ._version import version as _scm_version

        __version__ = _scm_version
    except ImportError:
        # Final fallback if setuptools_scm hasn't generated _version.py yet
        __version__ = "0.0.0.dev0"

from .json_solver import (
    ConfigurationError,
    load_config_from_file,
    solve_from_dict,
    solve_from_json,
)
from .mdp import MDP
from .result import MDPResult
from .solver import solve_mdp_value_iteration
from .validate import ValidationError, validate_mdp

__all__ = [
    "MDP",
    "MDPResult",
    "solve_mdp_value_iteration",
    "solve_from_json",
    "solve_from_dict",
    "validate_mdp",
    "ValidationError",
    "ConfigurationError",
    "load_config_from_file",
]
