{-| Module  : FiniteCategories
Description : An example of an arbitray diagram.
Copyright   : Guillaume Sabbagh 2021
License     : GPL-3
Maintainer  : guillaumesabbagh@protonmail.com
Stability   : experimental
Portability : portable

An example of an arbitray diagram. We select a square in a random composition graph.
-}
module ExampleDiagram.ExampleDiagram
(
    diag,
    main
)
where
    import              RandomCompositionGraph.RandomCompositionGraph
    import              System.Random                                   
    import              ExportGraphViz.ExportGraphViz                   (catToPdf,diagToPdf,diagToPdf2)
    import              Diagram.Diagram                                 (mkDiagram, src, completeMmap)
    import              CompositionGraph.CompositionGraph
    import              Utils.Sample
    import              FiniteCategory.FiniteCategory            hiding (FiniteCategoryError(..))
    import              Data.Maybe                                      (fromJust)
    import              Data.Map                                        (Map, fromList)
    import              ExampleCompositionGraph.ExampleCompositionGraph (square)
    import              Utils.AssociationList

    (rcg1,newGen) = (mkRandomCompositionGraph 20 25 3 (mkStdGen 12345))
    
    -- | We select a square in the random category.
    diag = fromJust $ mkDiagram square rcg1 (functToAssocList om (ob square)) fm
        where
            om 0 = 30
            om 1 = 20
            om 2 = 31
            om 3 = 29
            fm = completeMmap square rcg1 (functToAssocList om (ob square)) (functToAssocList fm_ (arrows square))
                where
                    fm_ x
                        | x == (head (genAr square 0 1)) = head $ genAr rcg1 30 20
                        | x == (head (genAr square 1 2)) = head $ genAr rcg1 20 31
                        | x == (head (genAr square 0 3)) = head $ genAr rcg1 30 29
                        | x == (head (genAr square 3 2)) = head $ genAr rcg1 29 31

    -- | Export the diagram as a pdf with GraphViz.
    main = do 
        putStrLn "Start of ExampleDiagram"
        catToPdf rcg1 "OutputGraphViz/Examples/Diagram/Diagram/rcg1"
        catToPdf square "OutputGraphViz/Examples/Diagram/Diagram/square"
        diagToPdf diag "OutputGraphViz/Examples/Diagram/Diagram/functor"
        diagToPdf2 diag "OutputGraphViz/Examples/Diagram/Diagram/diag"
        putStrLn "End of ExampleDiagram"