{-# LANGUAGE TemplateHaskell #-}

module Debian.VendorURI
    ( VendorURI(..)
    , vendorURI
    , parseVendorURI
    ) where

import Control.Lens (makeLenses, review)
import Debian.TH (here)
import Debian.URI (parseURI, URI(uriPath))
import Distribution.Pretty (prettyShow)
import Language.Haskell.TH.Syntax (Loc)
import System.FilePath (splitDirectories)

newtype VendorURI = VendorURI {VendorURI -> URI
_vendorURI :: URI} deriving (VendorURI -> VendorURI -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VendorURI -> VendorURI -> Bool
$c/= :: VendorURI -> VendorURI -> Bool
== :: VendorURI -> VendorURI -> Bool
$c== :: VendorURI -> VendorURI -> Bool
Eq, Eq VendorURI
VendorURI -> VendorURI -> Bool
VendorURI -> VendorURI -> Ordering
VendorURI -> VendorURI -> VendorURI
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
min :: VendorURI -> VendorURI -> VendorURI
$cmin :: VendorURI -> VendorURI -> VendorURI
max :: VendorURI -> VendorURI -> VendorURI
$cmax :: VendorURI -> VendorURI -> VendorURI
>= :: VendorURI -> VendorURI -> Bool
$c>= :: VendorURI -> VendorURI -> Bool
> :: VendorURI -> VendorURI -> Bool
$c> :: VendorURI -> VendorURI -> Bool
<= :: VendorURI -> VendorURI -> Bool
$c<= :: VendorURI -> VendorURI -> Bool
< :: VendorURI -> VendorURI -> Bool
$c< :: VendorURI -> VendorURI -> Bool
compare :: VendorURI -> VendorURI -> Ordering
$ccompare :: VendorURI -> VendorURI -> Ordering
Ord)

instance Show VendorURI where
    show :: VendorURI -> String
show (VendorURI URI
uri) = String
"VendorURI (fromJust (parseURIReference " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (forall a. Show a => a -> String
show URI
uri) forall a. [a] -> [a] -> [a]
++ String
"))"

$(makeLenses ''VendorURI)

parseVendorURI :: [Loc] -> String -> Maybe VendorURI
parseVendorURI :: [Loc] -> String -> Maybe VendorURI
parseVendorURI [Loc]
locs String
s = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Iso' VendorURI URI
vendorURI) (String -> Maybe URI
parseURI String
s)

-- toURI' :: VendorURI -> URI'
-- toURI' = URI' . show . view vendorURI