A cli database for some FFX stuff
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

module Overdrive
    ( Mix (Mix)
    , mixes
    ) where

import           Data.Char          (isSpace)
import           Data.List          (find)
import           Data.Maybe         (fromJust)
import           Data.PrintableText

import qualified Data.Map           as M
import qualified Data.Text          as T

import           Control.Lens
import           Control.Lens.TH

import           Item

data Mix = Mix Item Item
    deriving Show

instance Eq Mix where
    (Mix a b) == (Mix a' b') = (a == a' && b == b') || (a == b' && b == a')

data Effect = Effect
    { details      :: ItemDetails
    , effectTarget :: Target
    , _effect      :: [EffectType]
    }
    deriving (Show, Eq, Ord)

instance HasItemDetails Effect where
    itemDetails = lens details (\x y -> x { details = y })

instance HasTarget Effect where
    target = lens effectTarget (\x y -> x { effectTarget = y })

makeLenses ''Effect

mixdb :: M.Map Effect [Mix]
mixdb = M.fromList
    [ (getM "Firestorm", [Mix (getI "Bomb Core") (getI "Bomb Core")])
    , (getM "Ultra Potion", [Mix (getI "Potion") (getI "Potion")])
    , (getM "Blaster Mine",
        [Mix (getI "Grenade") (getI "Eye Drops"), Mix (getI "Grenade") (getI "Power Sphere")])
    , (getM "Frag Grenade", [Mix (getI "Power Sphere") (getI "Power Sphere")])
    , (getM "Mana", [Mix (getI "Ether") (getI "Speed Sphere")])
    ]
    where
        getI = fromJust . searchItems
        getM = fromJust . searchMixes
        mkName = fromJust . fromText
        searchMixes = flip find mixes . searchFilter
        searchItems = flip find items . searchFilter
        searchFilter haystack = (== haystack) . unPrintableText . view name

mixes :: [Effect]
mixes =
    [ Effect (ItemDetails (mkName "Firestorm") "Deals damage to all enemies") Multi [Damage $ Elemental Fire]
    , Effect (ItemDetails (mkName "Ultra Potion") "Fully restore all allies HP") Multi [health id RestoreFull]
    , Effect (ItemDetails (mkName "Blaster Mine") "Deal damage to all enemies as well as inflict blindness, sleep and silence")
        Multi [Damage Normal, Remove (Ailment Darkness), Remove (Ailment Silence), Remove (Ailment Sleep)]
    , Effect (ItemDetails (mkName "Frag Grenade") "Deal damage to all enemies") Multi [Damage Normal]
    , Effect (ItemDetails (mkName "Mana") "Doubles Max Mana") Single []
    ]
    where
        mkName = fromJust . fromText