-- | A more general version of 'mkRenderRouteInstance' which takes an
-- additional context.

mkRenderRouteInstance' :: Cxt -> Type -> [ResourceTree Type] -> Q [Dec]
mkRenderRouteInstance' cxt typ ress = do
    cls <- mkRenderRouteClauses ress
    (cons, decs) <- mkRouteCons ress
#if MIN_VERSION_template_haskell(2,11,0)
    did <- DataInstD [] ''Route [typ] Nothing cons <$> mapM conT clazzes
#else
    let did = DataInstD [] ''Route [typ] cons clazzes
#endif
    return $ instanceD cxt (ConT ''RenderRoute `AppT` typ)
        [ did
        , FunD (mkName "renderRoute") cls
        ] : decs
  where
    clazzes = [''Show, ''Eq, ''Read]

#if MIN_VERSION_template_haskell(2,11,0)
mkRenderRouteInstance' :: Cxt -> Type -> [ResourceTree Type] -> Q [Dec]
mkRenderRouteInstance' cxt typ ress = do
    cls <- mkRenderRouteClauses ress
    (cons, decs) <- mkRouteCons ress
#if MIN_VERSION_template_haskell(2,11,0)
    did <- DataInstD [] ''Route [typ] Nothing cons <$> mapM conT clazzes
#else
    let did = DataInstD [] ''Route [typ] cons clazzes
#endif
    return $ instanceD cxt (ConT ''RenderRoute `AppT` typ)
        [ did
        , FunD (mkName "renderRoute") cls
        ] : decs
  where
    clazzes = [''Show, ''Eq, ''Read]

#if MIN_VERSION_template_haskell(2,11,0)
mkRenderRouteInstance' cxt typ ress = do
    cls <- mkRenderRouteClauses ress
    (cons, decs) <- mkRouteCons ress
#if MIN_VERSION_template_haskell(2,11,0)
    did <- DataInstD [] ''Route [typ] Nothing cons <$> mapM conT clazzes
#else
    let did = DataInstD [] ''Route [typ] cons clazzes
#endif
    return $ instanceD cxt (ConT ''RenderRoute `AppT` typ)
        [ did
        , FunD (mkName "renderRoute") cls
        ] : decs
  where
    clazzes = [''Show, ''Eq, ''Read]

#if MIN_VERSION_template_haskell(2,11,0)