import Game.Cosanostra.Glue.Instances.JSON ()

import Game.Cosanostra.Action
import Game.Cosanostra.Lenses

import Control.Lens
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map.Strict as M
import Data.Yaml
import System.Environment

main :: IO ()
main = do
    [gamePath] <- getArgs
    game <- either error id <$> decodeEither <$> BS.readFile gamePath

    let l = M.fromListWith (M.unionWith (++)) [( actTurn act
                                               , M.fromList [(actPhase act, [act])]
                                               )
                                               | act <- game ^. gameHistory
                                               ]

    BS.putStrLn $ encode l
