{-# LANGUAGE TemplateHaskell #-}

module BtcLsp.Yesod.Data.Language where

import BtcLsp.Import.External
import qualified Data.Text as T
import Database.Persist.TH
import qualified Universum

data Code
  = En
  | Ru
  deriving stock
    ( Int -> Code -> ShowS
[Code] -> ShowS
Code -> String
(Int -> Code -> ShowS)
-> (Code -> String) -> ([Code] -> ShowS) -> Show Code
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Code] -> ShowS
$cshowList :: [Code] -> ShowS
show :: Code -> String
$cshow :: Code -> String
showsPrec :: Int -> Code -> ShowS
$cshowsPrec :: Int -> Code -> ShowS
Show,
      ReadPrec [Code]
ReadPrec Code
Int -> ReadS Code
ReadS [Code]
(Int -> ReadS Code)
-> ReadS [Code] -> ReadPrec Code -> ReadPrec [Code] -> Read Code
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Code]
$creadListPrec :: ReadPrec [Code]
readPrec :: ReadPrec Code
$creadPrec :: ReadPrec Code
readList :: ReadS [Code]
$creadList :: ReadS [Code]
readsPrec :: Int -> ReadS Code
$creadsPrec :: Int -> ReadS Code
Read,
      Code -> Code -> Bool
(Code -> Code -> Bool) -> (Code -> Code -> Bool) -> Eq Code
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Code -> Code -> Bool
$c/= :: Code -> Code -> Bool
== :: Code -> Code -> Bool
$c== :: Code -> Code -> Bool
Eq,
      Int -> Code
Code -> Int
Code -> [Code]
Code -> Code
Code -> Code -> [Code]
Code -> Code -> Code -> [Code]
(Code -> Code)
-> (Code -> Code)
-> (Int -> Code)
-> (Code -> Int)
-> (Code -> [Code])
-> (Code -> Code -> [Code])
-> (Code -> Code -> [Code])
-> (Code -> Code -> Code -> [Code])
-> Enum Code
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Code -> Code -> Code -> [Code]
$cenumFromThenTo :: Code -> Code -> Code -> [Code]
enumFromTo :: Code -> Code -> [Code]
$cenumFromTo :: Code -> Code -> [Code]
enumFromThen :: Code -> Code -> [Code]
$cenumFromThen :: Code -> Code -> [Code]
enumFrom :: Code -> [Code]
$cenumFrom :: Code -> [Code]
fromEnum :: Code -> Int
$cfromEnum :: Code -> Int
toEnum :: Int -> Code
$ctoEnum :: Int -> Code
pred :: Code -> Code
$cpred :: Code -> Code
succ :: Code -> Code
$csucc :: Code -> Code
Enum,
      Code
Code -> Code -> Bounded Code
forall a. a -> a -> Bounded a
maxBound :: Code
$cmaxBound :: Code
minBound :: Code
$cminBound :: Code
Bounded
    )

derivePersistField "Code"

codeList :: [Code]
codeList :: [Code]
codeList =
  [Code
forall a. Bounded a => a
minBound .. Code
forall a. Bounded a => a
maxBound]

instance PathPiece Code where
  fromPathPiece :: Text -> Maybe Code
  fromPathPiece :: Text -> Maybe Code
fromPathPiece =
    String -> Maybe Code
forall a. Read a => String -> Maybe a
readMaybe
      (String -> Maybe Code) -> (Text -> String) -> Text -> Maybe Code
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
      (Text -> String) -> (Text -> Text) -> Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toTitle
  toPathPiece :: Code -> Text
  toPathPiece :: Code -> Text
toPathPiece =
    Text -> Text
T.toLower
      (Text -> Text) -> (Code -> Text) -> Code -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
      (String -> Text) -> (Code -> String) -> Code -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Code -> String
forall b a. (Show a, IsString b) => a -> b
Universum.show