-- |
--
-- Module      : Ronn.ManRef
-- Copyright   : (c) 2024 Patrick Brisbin
-- License     : AGPL-3
-- Maintainer  : pbrisbin@gmail.com
-- Stability   : experimental
-- Portability : POSIX
module Ronn.ManRef
  ( ManRef (..)
  , ManSection (..)
  , manSectionNumber
  )
where

import Prelude

import Data.Ord
import Data.Text

data ManRef = ManRef
  { ManRef -> Text
name :: Text
  , ManRef -> ManSection
section :: ManSection
  }
  deriving stock (ManRef -> ManRef -> Bool
(ManRef -> ManRef -> Bool)
-> (ManRef -> ManRef -> Bool) -> Eq ManRef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ManRef -> ManRef -> Bool
== :: ManRef -> ManRef -> Bool
$c/= :: ManRef -> ManRef -> Bool
/= :: ManRef -> ManRef -> Bool
Eq, Int -> ManRef -> ShowS
[ManRef] -> ShowS
ManRef -> String
(Int -> ManRef -> ShowS)
-> (ManRef -> String) -> ([ManRef] -> ShowS) -> Show ManRef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ManRef -> ShowS
showsPrec :: Int -> ManRef -> ShowS
$cshow :: ManRef -> String
show :: ManRef -> String
$cshowList :: [ManRef] -> ShowS
showList :: [ManRef] -> ShowS
Show)

instance Ord ManRef where
  compare :: ManRef -> ManRef -> Ordering
compare ManRef
a ManRef
b = (ManRef -> ManSection) -> ManRef -> ManRef -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (.section) ManRef
a ManRef
b Ordering -> Ordering -> Ordering
forall a. Semigroup a => a -> a -> a
<> (ManRef -> Text) -> ManRef -> ManRef -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (.name) ManRef
a ManRef
b

data ManSection
  = ManSection1
  | ManSection2
  | ManSection3
  | ManSection4
  | ManSection5
  | ManSection6
  | ManSection7
  | ManSection8
  deriving stock (ManSection -> ManSection -> Bool
(ManSection -> ManSection -> Bool)
-> (ManSection -> ManSection -> Bool) -> Eq ManSection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ManSection -> ManSection -> Bool
== :: ManSection -> ManSection -> Bool
$c/= :: ManSection -> ManSection -> Bool
/= :: ManSection -> ManSection -> Bool
Eq, Eq ManSection
Eq ManSection =>
(ManSection -> ManSection -> Ordering)
-> (ManSection -> ManSection -> Bool)
-> (ManSection -> ManSection -> Bool)
-> (ManSection -> ManSection -> Bool)
-> (ManSection -> ManSection -> Bool)
-> (ManSection -> ManSection -> ManSection)
-> (ManSection -> ManSection -> ManSection)
-> Ord ManSection
ManSection -> ManSection -> Bool
ManSection -> ManSection -> Ordering
ManSection -> ManSection -> ManSection
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ManSection -> ManSection -> Ordering
compare :: ManSection -> ManSection -> Ordering
$c< :: ManSection -> ManSection -> Bool
< :: ManSection -> ManSection -> Bool
$c<= :: ManSection -> ManSection -> Bool
<= :: ManSection -> ManSection -> Bool
$c> :: ManSection -> ManSection -> Bool
> :: ManSection -> ManSection -> Bool
$c>= :: ManSection -> ManSection -> Bool
>= :: ManSection -> ManSection -> Bool
$cmax :: ManSection -> ManSection -> ManSection
max :: ManSection -> ManSection -> ManSection
$cmin :: ManSection -> ManSection -> ManSection
min :: ManSection -> ManSection -> ManSection
Ord, ManSection
ManSection -> ManSection -> Bounded ManSection
forall a. a -> a -> Bounded a
$cminBound :: ManSection
minBound :: ManSection
$cmaxBound :: ManSection
maxBound :: ManSection
Bounded, Int -> ManSection
ManSection -> Int
ManSection -> [ManSection]
ManSection -> ManSection
ManSection -> ManSection -> [ManSection]
ManSection -> ManSection -> ManSection -> [ManSection]
(ManSection -> ManSection)
-> (ManSection -> ManSection)
-> (Int -> ManSection)
-> (ManSection -> Int)
-> (ManSection -> [ManSection])
-> (ManSection -> ManSection -> [ManSection])
-> (ManSection -> ManSection -> [ManSection])
-> (ManSection -> ManSection -> ManSection -> [ManSection])
-> Enum ManSection
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ManSection -> ManSection
succ :: ManSection -> ManSection
$cpred :: ManSection -> ManSection
pred :: ManSection -> ManSection
$ctoEnum :: Int -> ManSection
toEnum :: Int -> ManSection
$cfromEnum :: ManSection -> Int
fromEnum :: ManSection -> Int
$cenumFrom :: ManSection -> [ManSection]
enumFrom :: ManSection -> [ManSection]
$cenumFromThen :: ManSection -> ManSection -> [ManSection]
enumFromThen :: ManSection -> ManSection -> [ManSection]
$cenumFromTo :: ManSection -> ManSection -> [ManSection]
enumFromTo :: ManSection -> ManSection -> [ManSection]
$cenumFromThenTo :: ManSection -> ManSection -> ManSection -> [ManSection]
enumFromThenTo :: ManSection -> ManSection -> ManSection -> [ManSection]
Enum, Int -> ManSection -> ShowS
[ManSection] -> ShowS
ManSection -> String
(Int -> ManSection -> ShowS)
-> (ManSection -> String)
-> ([ManSection] -> ShowS)
-> Show ManSection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ManSection -> ShowS
showsPrec :: Int -> ManSection -> ShowS
$cshow :: ManSection -> String
show :: ManSection -> String
$cshowList :: [ManSection] -> ShowS
showList :: [ManSection] -> ShowS
Show)

manSectionNumber :: ManSection -> Int
manSectionNumber :: ManSection -> Int
manSectionNumber = (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int -> Int) -> (ManSection -> Int) -> ManSection -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ManSection -> Int
forall a. Enum a => a -> Int
fromEnum