{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}

module Data.Aviation.Casa.AbbreviationsAndAcronyms.Render.Score(
  HasScore(..)
, HasShowScore(..)
) where

import Control.Category(id)
import Control.Lens(Lens', Getter, to)
import Data.Functor(fmap)
import Data.Int(Int)
import Data.Monoid.Textual(TextualMonoid)
import Data.String(String)
import Prelude(show)
import Text.Fuzzy(Fuzzy(Fuzzy))

class HasScore a where
  score ::
    Lens'
      a
      Int

instance HasScore Int where
  score :: (Int -> f Int) -> Int -> f Int
score =
    (Int -> f Int) -> Int -> f Int
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id

instance TextualMonoid s => HasScore (Fuzzy a s) where
  score :: (Int -> f Int) -> Fuzzy a s -> f (Fuzzy a s)
score Int -> f Int
f (Fuzzy a
x s
o Int
s) =
    (Int -> Fuzzy a s) -> f Int -> f (Fuzzy a s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Int
t -> a -> s -> Int -> Fuzzy a s
forall t s. t -> s -> Int -> Fuzzy t s
Fuzzy a
x s
o Int
t) (Int -> f Int
f Int
s)

class HasShowScore a where
  showScore ::
    Getter
      a
      String

instance HasShowScore String where
  showScore :: (String -> f String) -> String -> f String
showScore =
    (String -> f String) -> String -> f String
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id

instance HasShowScore Int where
  showScore :: (String -> f String) -> Int -> f Int
showScore =
    (Int -> String) -> (String -> f String) -> Int -> f Int
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to Int -> String
forall a. Show a => a -> String
show

instance TextualMonoid s => HasShowScore (Fuzzy a s) where
  showScore :: (String -> f String) -> Fuzzy a s -> f (Fuzzy a s)
showScore =
    (Fuzzy a s -> String)
-> (String -> f String) -> Fuzzy a s -> f (Fuzzy a s)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (\(Fuzzy a
_ s
_ Int
s) -> Int -> String
forall a. Show a => a -> String
show Int
s)