#!/usr/bin/env python3
"""Portfolio module — backward-compatible wrapper around game_engine.

All operations now delegate to game_engine using the default game and 'case' player.
"""

import json
import game_engine

INITIAL_CASH = 100_000.0


def _default():
    """Get default game ID."""
    return game_engine.get_default_game_id() or game_engine.ensure_default_game()


def buy(ticker, shares, price, reason="GARP signal"):
    return game_engine.buy(_default(), "case", ticker, shares, price, reason)


def sell(ticker, shares=None, price=None, reason="GARP exit"):
    return game_engine.sell(_default(), "case", ticker, shares, price, reason)


def update_price(ticker, price):
    game_engine.update_price(_default(), "case", ticker, price)


def get_portfolio():
    return game_engine.get_portfolio(_default(), "case")


def get_history():
    return game_engine.get_trades(_default(), "case")


def daily_snapshot():
    return game_engine.daily_snapshot(_default(), "case")


def get_snapshots():
    return game_engine.get_snapshots(_default(), "case")


if __name__ == "__main__":
    p = get_portfolio()
    if p:
        print(json.dumps(p, indent=2))
    else:
        print("No default game found. Run: python3 game_engine.py")
