{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}

module Data.BCP47.Internal.Subtags
  ( Subtags(..)
  ) where

import Data.BCP47.Internal.Extension
import Data.BCP47.Internal.LanguageExtension
import Data.BCP47.Internal.PrivateUse
import Data.BCP47.Internal.Region
import Data.BCP47.Internal.Script
import Data.BCP47.Internal.Variant
import GHC.Generics (Generic)
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Arbitrary.Generic
import Test.QuickCheck.Gen (oneof)

data Subtags
  = SpecifyLanguageExtension LanguageExtension
  | SpecifyScript Script
  | SpecifyRegion Country
  | SpecifyVariant Variant
  | SpecifyExtension Extension
  | SpecifyPrivateUse PrivateUse
  deriving stock (Int -> Subtags -> ShowS
[Subtags] -> ShowS
Subtags -> String
(Int -> Subtags -> ShowS)
-> (Subtags -> String) -> ([Subtags] -> ShowS) -> Show Subtags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Subtags] -> ShowS
$cshowList :: [Subtags] -> ShowS
show :: Subtags -> String
$cshow :: Subtags -> String
showsPrec :: Int -> Subtags -> ShowS
$cshowsPrec :: Int -> Subtags -> ShowS
Show, Subtags -> Subtags -> Bool
(Subtags -> Subtags -> Bool)
-> (Subtags -> Subtags -> Bool) -> Eq Subtags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Subtags -> Subtags -> Bool
$c/= :: Subtags -> Subtags -> Bool
== :: Subtags -> Subtags -> Bool
$c== :: Subtags -> Subtags -> Bool
Eq, Eq Subtags
Eq Subtags
-> (Subtags -> Subtags -> Ordering)
-> (Subtags -> Subtags -> Bool)
-> (Subtags -> Subtags -> Bool)
-> (Subtags -> Subtags -> Bool)
-> (Subtags -> Subtags -> Bool)
-> (Subtags -> Subtags -> Subtags)
-> (Subtags -> Subtags -> Subtags)
-> Ord Subtags
Subtags -> Subtags -> Bool
Subtags -> Subtags -> Ordering
Subtags -> Subtags -> Subtags
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 :: Subtags -> Subtags -> Subtags
$cmin :: Subtags -> Subtags -> Subtags
max :: Subtags -> Subtags -> Subtags
$cmax :: Subtags -> Subtags -> Subtags
>= :: Subtags -> Subtags -> Bool
$c>= :: Subtags -> Subtags -> Bool
> :: Subtags -> Subtags -> Bool
$c> :: Subtags -> Subtags -> Bool
<= :: Subtags -> Subtags -> Bool
$c<= :: Subtags -> Subtags -> Bool
< :: Subtags -> Subtags -> Bool
$c< :: Subtags -> Subtags -> Bool
compare :: Subtags -> Subtags -> Ordering
$ccompare :: Subtags -> Subtags -> Ordering
$cp1Ord :: Eq Subtags
Ord, (forall x. Subtags -> Rep Subtags x)
-> (forall x. Rep Subtags x -> Subtags) -> Generic Subtags
forall x. Rep Subtags x -> Subtags
forall x. Subtags -> Rep Subtags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Subtags x -> Subtags
$cfrom :: forall x. Subtags -> Rep Subtags x
Generic)

instance Arbitrary Subtags where
  arbitrary :: Gen Subtags
arbitrary = [Gen Subtags] -> Gen Subtags
forall a. [Gen a] -> Gen a
oneof
    [ LanguageExtension -> Subtags
SpecifyLanguageExtension (LanguageExtension -> Subtags)
-> Gen LanguageExtension -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen LanguageExtension
forall a. Arbitrary a => Gen a
arbitrary
    , Script -> Subtags
SpecifyScript (Script -> Subtags) -> Gen Script -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Script
forall a. Arbitrary a => Gen a
arbitrary
    , Country -> Subtags
SpecifyRegion (Country -> Subtags) -> Gen Country -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Country
forall a (ga :: * -> *).
(Generic a, GArbitrary ga, ga ~ Rep a) =>
Gen a
genericArbitrary
    , Variant -> Subtags
SpecifyVariant (Variant -> Subtags) -> Gen Variant -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Variant
forall a. Arbitrary a => Gen a
arbitrary
    , Extension -> Subtags
SpecifyExtension (Extension -> Subtags) -> Gen Extension -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Extension
forall a. Arbitrary a => Gen a
arbitrary
    , PrivateUse -> Subtags
SpecifyPrivateUse (PrivateUse -> Subtags) -> Gen PrivateUse -> Gen Subtags
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen PrivateUse
forall a. Arbitrary a => Gen a
arbitrary
    ]