{-# LANGUAGE MultiWayIf #-}
-- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator.
{-# LANGUAGE OverloadedStrings #-}

-- | Contains the types generated from the schema LineItemRefund
module RecurlyClient.Types.LineItemRefund where

import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.ByteString
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified RecurlyClient.Common
import RecurlyClient.TypeAlias
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.LineItemRefund@ in the specification.
data LineItemRefund = LineItemRefund
    { LineItemRefund -> Maybe Float
lineItemRefundAmount :: (GHC.Maybe.Maybe GHC.Types.Float)
    -- ^ amount: The specific amount to be refunded from the adjustment. Must be less than or equal to the adjustment\'s remaining balance. If \`quantity\`, \`quantity_decimal\` and \`percentage\` are not present, \`amount\` is required. If \`quantity\`, \`quantity_decimal\`, or \`percentage\` is present, \`amount\` must be absent.
    , LineItemRefund -> Maybe Text
lineItemRefundId :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ id
    --
    -- Constraints:
    --
    -- * Maximum length of 13
    , LineItemRefund -> Maybe Int
lineItemRefundPercentage :: (GHC.Maybe.Maybe GHC.Types.Int)
    -- ^ percentage: The percentage of the adjustment\'s remaining balance to refund. If \`quantity\`, \`quantity_decimal\` and \`amount_in_cents\` are not present, \`percentage\` is required. If \`quantity\`, \`quantity_decimal\` or \`amount_in_cents\` is present, \`percentage\` must be absent.
    --
    -- Constraints:
    --
    -- * Maxium  of 100.0
    -- * Minimum  of 1.0
    , LineItemRefund -> Maybe Bool
lineItemRefundProrate :: (GHC.Maybe.Maybe GHC.Types.Bool)
    -- ^ prorate: Set to \`true\` if the line item should be prorated; set to \`false\` if not.
    -- This can only be used on line items that have a start and end date.
    , LineItemRefund -> Maybe Int
lineItemRefundQuantity :: (GHC.Maybe.Maybe GHC.Types.Int)
    -- ^ quantity: Line item quantity to be refunded. Must be less than or equal to the \`quantity_remaining\`. If \`quantity_decimal\`, \`amount\`, and \`percentage\` are not present, \`quantity\` is required. If \`amount\` or \`percentage\` is present, \`quantity\` must be absent.
    , LineItemRefund -> Maybe Text
lineItemRefundQuantity_decimal :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ quantity_decimal: Decimal quantity to refund. The \`quantity_decimal\` will be used to refund charges that has a NOT null quantity decimal. Must be less than or equal to the \`quantity_decimal_remaining\`. If \`quantity\`, \`amount\`, and \`percentage\` are not present, \`quantity_decimal\` is required. If \`amount\` or \`percentage\` is present, \`quantity_decimal\` must be absent. The Decimal Quantity feature must be enabled to utilize this field.
    }
    deriving
        ( Int -> LineItemRefund -> ShowS
[LineItemRefund] -> ShowS
LineItemRefund -> String
(Int -> LineItemRefund -> ShowS)
-> (LineItemRefund -> String)
-> ([LineItemRefund] -> ShowS)
-> Show LineItemRefund
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LineItemRefund -> ShowS
showsPrec :: Int -> LineItemRefund -> ShowS
$cshow :: LineItemRefund -> String
show :: LineItemRefund -> String
$cshowList :: [LineItemRefund] -> ShowS
showList :: [LineItemRefund] -> ShowS
GHC.Show.Show
        , LineItemRefund -> LineItemRefund -> Bool
(LineItemRefund -> LineItemRefund -> Bool)
-> (LineItemRefund -> LineItemRefund -> Bool) -> Eq LineItemRefund
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LineItemRefund -> LineItemRefund -> Bool
== :: LineItemRefund -> LineItemRefund -> Bool
$c/= :: LineItemRefund -> LineItemRefund -> Bool
/= :: LineItemRefund -> LineItemRefund -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON LineItemRefund where
    toJSON :: LineItemRefund -> Value
toJSON LineItemRefund
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair] -> (Float -> [Pair]) -> Maybe Float -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Float -> Pair) -> Float -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"amount" Key -> Float -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Float
lineItemRefundAmount LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"id" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Text
lineItemRefundId LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Int -> [Pair]) -> Maybe Int -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Int -> Pair) -> Int -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"percentage" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Int
lineItemRefundPercentage LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Bool -> [Pair]) -> Maybe Bool -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Bool -> Pair) -> Bool -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"prorate" Key -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Bool
lineItemRefundProrate LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Int -> [Pair]) -> Maybe Int -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Int -> Pair) -> Int -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"quantity" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Int
lineItemRefundQuantity LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"quantity_decimal" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Text
lineItemRefundQuantity_decimal LineItemRefund
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: LineItemRefund -> Encoding
toEncoding LineItemRefund
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ([Series] -> Series
forall a. Monoid a => [a] -> a
GHC.Base.mconcat ([[Series]] -> [Series]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Series] -> (Float -> [Series]) -> Maybe Float -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Float -> Series) -> Float -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"amount" Key -> Float -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Float
lineItemRefundAmount LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Text -> [Series]) -> Maybe Text -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"id" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Text
lineItemRefundId LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Int -> [Series]) -> Maybe Int -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Int -> Series) -> Int -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"percentage" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Int
lineItemRefundPercentage LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Bool -> [Series]) -> Maybe Bool -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Bool -> Series) -> Bool -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"prorate" Key -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Bool
lineItemRefundProrate LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Int -> [Series]) -> Maybe Int -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Int -> Series) -> Int -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"quantity" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Int
lineItemRefundQuantity LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Text -> [Series]) -> Maybe Text -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"quantity_decimal" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (LineItemRefund -> Maybe Text
lineItemRefundQuantity_decimal LineItemRefund
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON LineItemRefund where
    parseJSON :: Value -> Parser LineItemRefund
parseJSON = String
-> (Object -> Parser LineItemRefund)
-> Value
-> Parser LineItemRefund
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"LineItemRefund" (\Object
obj -> ((((((Maybe Float
 -> Maybe Text
 -> Maybe Int
 -> Maybe Bool
 -> Maybe Int
 -> Maybe Text
 -> LineItemRefund)
-> Parser
     (Maybe Float
      -> Maybe Text
      -> Maybe Int
      -> Maybe Bool
      -> Maybe Int
      -> Maybe Text
      -> LineItemRefund)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Float
-> Maybe Text
-> Maybe Int
-> Maybe Bool
-> Maybe Int
-> Maybe Text
-> LineItemRefund
LineItemRefund Parser
  (Maybe Float
   -> Maybe Text
   -> Maybe Int
   -> Maybe Bool
   -> Maybe Int
   -> Maybe Text
   -> LineItemRefund)
-> Parser (Maybe Float)
-> Parser
     (Maybe Text
      -> Maybe Int
      -> Maybe Bool
      -> Maybe Int
      -> Maybe Text
      -> LineItemRefund)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Float)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"amount")) Parser
  (Maybe Text
   -> Maybe Int
   -> Maybe Bool
   -> Maybe Int
   -> Maybe Text
   -> LineItemRefund)
-> Parser (Maybe Text)
-> Parser
     (Maybe Int
      -> Maybe Bool -> Maybe Int -> Maybe Text -> LineItemRefund)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"id")) Parser
  (Maybe Int
   -> Maybe Bool -> Maybe Int -> Maybe Text -> LineItemRefund)
-> Parser (Maybe Int)
-> Parser (Maybe Bool -> Maybe Int -> Maybe Text -> LineItemRefund)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"percentage")) Parser (Maybe Bool -> Maybe Int -> Maybe Text -> LineItemRefund)
-> Parser (Maybe Bool)
-> Parser (Maybe Int -> Maybe Text -> LineItemRefund)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"prorate")) Parser (Maybe Int -> Maybe Text -> LineItemRefund)
-> Parser (Maybe Int) -> Parser (Maybe Text -> LineItemRefund)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"quantity")) Parser (Maybe Text -> LineItemRefund)
-> Parser (Maybe Text) -> Parser LineItemRefund
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"quantity_decimal"))

-- | Create a new 'LineItemRefund' with all required fields.
mkLineItemRefund :: LineItemRefund
mkLineItemRefund :: LineItemRefund
mkLineItemRefund =
    LineItemRefund
        { lineItemRefundAmount :: Maybe Float
lineItemRefundAmount = Maybe Float
forall a. Maybe a
GHC.Maybe.Nothing
        , lineItemRefundId :: Maybe Text
lineItemRefundId = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        , lineItemRefundPercentage :: Maybe Int
lineItemRefundPercentage = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing
        , lineItemRefundProrate :: Maybe Bool
lineItemRefundProrate = Maybe Bool
forall a. Maybe a
GHC.Maybe.Nothing
        , lineItemRefundQuantity :: Maybe Int
lineItemRefundQuantity = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing
        , lineItemRefundQuantity_decimal :: Maybe Text
lineItemRefundQuantity_decimal = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        }