{-# LANGUAGE UndecidableInstances #-}

module ZkFold.Base.Protocol.Plonkup.Witness where

import           Control.Applicative                     ((<*>))
import           Data.Functor                            ((<$>))
import           Data.Functor.Classes                    (Show1)
import           Data.List                               ((++))
import           Test.QuickCheck                         (Arbitrary (..), Arbitrary1, arbitrary1)
import           Text.Show                               (Show, show)

import           ZkFold.Base.Algebra.EllipticCurve.Class (CyclicGroup (..))

data PlonkupWitnessInput p i g = PlonkupWitnessInput
  { forall (p :: Type -> Type) (i :: Type -> Type) g.
PlonkupWitnessInput p i g -> p (ScalarFieldOf g)
payloadInput :: p (ScalarFieldOf g)
  , forall (p :: Type -> Type) (i :: Type -> Type) g.
PlonkupWitnessInput p i g -> i (ScalarFieldOf g)
witnessInput :: i (ScalarFieldOf g)
  }

instance (Show1 p, Show1 i, Show (ScalarFieldOf g))
  => Show (PlonkupWitnessInput p i g) where
    show :: PlonkupWitnessInput p i g -> String
show (PlonkupWitnessInput p (ScalarFieldOf g)
p i (ScalarFieldOf g)
v) = String
"Plonkup Witness Input: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ p (ScalarFieldOf g) -> String
forall a. Show a => a -> String
show p (ScalarFieldOf g)
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", " String -> ShowS
forall a. [a] -> [a] -> [a]
++ i (ScalarFieldOf g) -> String
forall a. Show a => a -> String
show i (ScalarFieldOf g)
v

instance (Arbitrary1 p, Arbitrary1 i, Arbitrary (ScalarFieldOf g))
  => Arbitrary (PlonkupWitnessInput p i g) where
    arbitrary :: Gen (PlonkupWitnessInput p i g)
arbitrary = p (ScalarFieldOf g)
-> i (ScalarFieldOf g) -> PlonkupWitnessInput p i g
forall (p :: Type -> Type) (i :: Type -> Type) g.
p (ScalarFieldOf g)
-> i (ScalarFieldOf g) -> PlonkupWitnessInput p i g
PlonkupWitnessInput (p (ScalarFieldOf g)
 -> i (ScalarFieldOf g) -> PlonkupWitnessInput p i g)
-> Gen (p (ScalarFieldOf g))
-> Gen (i (ScalarFieldOf g) -> PlonkupWitnessInput p i g)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (p (ScalarFieldOf g))
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
Gen (f a)
arbitrary1 Gen (i (ScalarFieldOf g) -> PlonkupWitnessInput p i g)
-> Gen (i (ScalarFieldOf g)) -> Gen (PlonkupWitnessInput p i g)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Gen (i (ScalarFieldOf g))
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
Gen (f a)
arbitrary1