module Dodge.Module 
    ( moduleSizes
    , moduleStrings
    , moduleName
    ) where
import Dodge.Data
--import Dodge.Combine.Module

import qualified Data.Map.Strict as M
--import Control.Lens
--import Data.Maybe

--moduleSizes :: Item -> Int
--moduleSizes = moduleFold (+) (^? modSize) 0
moduleSizes :: Item -> Int
moduleSizes = sum . fmap moduleSize . _iyModules . _itType

moduleSize :: ItemModuleType -> Int
moduleSize imt = case imt of
    EMPTYMODULE -> 0
    _ -> 1

moduleStrings :: Item -> [String]
moduleStrings = M.elems . M.mapMaybe moduleName . _iyModules . _itType

moduleName :: ItemModuleType -> Maybe String
moduleName imt = case imt of
    EMPTYMODULE -> Nothing
    DRUMMAG     -> Just "+DRUM MAG"
    BELTMAG     -> Just "+BELT FEED"
    MAGNETMAG   -> Just "+MAGNET FEED"
    INCENDBUL   -> Just "+INCENDIARY"
    BOUNCEBUL   -> Just "+BOUNCE"
    STATICBUL   -> Just "+STATIC"
    CONCUSBUL   -> Just "+CONCUSS"
    TARGCR      -> Just "+CREATURETARGETING"
    TARGLAS     -> Just "+LASERTARGETING"
    TARGPOS     -> Just "+POSTIONALTARGETING"
    MAGNETTRAJ  -> Just "+MAGNETTRAJECTORY" 
    FLECHETRAJ  -> Just "+FLECHETTETRAJECTORY"
    BEZIERTRAJ  -> Just "+BEZIERTRAJECTORY" 
    INCENDLAS   -> Just "+INCENDIARY"
    SPLITLAS    -> Just "+SPLIT"
    STATICLAS   -> Just "+STATIC" 
    WEPTELE     -> Just "+DIRECTEDTELE"
    LAUNCHHOME  -> Just "+TARGET HOMING"
    EXTRABATTERY -> Just "+BATTERY"

--moduleFold :: (m -> m -> m) -> (ItemModule -> Maybe m) -> m -> Item -> m
--moduleFold g f e = foldr (g . fromMaybe e . f) e 
--    . fmap fromModuleType 
--    . _iyModules
--    . _itType
