{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.HoneyCode.Types.ResultSet
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.HoneyCode.Types.ResultSet where

import qualified Amazonka.Core as Core
import Amazonka.HoneyCode.Types.ColumnMetadata
import Amazonka.HoneyCode.Types.ResultRow
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | ResultSet contains the results of the request for a single block or list
-- defined on the screen.
--
-- /See:/ 'newResultSet' smart constructor.
data ResultSet = ResultSet'
  { -- | List of headers for all the data cells in the block. The header
    -- identifies the name and default format of the data cell. Data cells
    -- appear in the same order in all rows as defined in the header. The names
    -- and formats are not repeated in the rows. If a particular row does not
    -- have a value for a data cell, a blank value is used.
    --
    -- For example, a task list that displays the task name, due date and
    -- assigned person might have headers [ { \"name\": \"Task Name\"},
    -- {\"name\": \"Due Date\", \"format\": \"DATE\"}, {\"name\": \"Assigned\",
    -- \"format\": \"CONTACT\"} ]. Every row in the result will have the task
    -- name as the first item, due date as the second item and assigned person
    -- as the third item. If a particular task does not have a due date, that
    -- row will still have a blank value in the second element and the assigned
    -- person will still be in the third element.
    ResultSet -> [ColumnMetadata]
headers :: [ColumnMetadata],
    -- | List of rows returned by the request. Each row has a row Id and a list
    -- of data cells in that row. The data cells will be present in the same
    -- order as they are defined in the header.
    ResultSet -> [ResultRow]
rows :: [ResultRow]
  }
  deriving (ResultSet -> ResultSet -> Bool
(ResultSet -> ResultSet -> Bool)
-> (ResultSet -> ResultSet -> Bool) -> Eq ResultSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultSet -> ResultSet -> Bool
$c/= :: ResultSet -> ResultSet -> Bool
== :: ResultSet -> ResultSet -> Bool
$c== :: ResultSet -> ResultSet -> Bool
Prelude.Eq, Int -> ResultSet -> ShowS
[ResultSet] -> ShowS
ResultSet -> String
(Int -> ResultSet -> ShowS)
-> (ResultSet -> String)
-> ([ResultSet] -> ShowS)
-> Show ResultSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultSet] -> ShowS
$cshowList :: [ResultSet] -> ShowS
show :: ResultSet -> String
$cshow :: ResultSet -> String
showsPrec :: Int -> ResultSet -> ShowS
$cshowsPrec :: Int -> ResultSet -> ShowS
Prelude.Show, (forall x. ResultSet -> Rep ResultSet x)
-> (forall x. Rep ResultSet x -> ResultSet) -> Generic ResultSet
forall x. Rep ResultSet x -> ResultSet
forall x. ResultSet -> Rep ResultSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResultSet x -> ResultSet
$cfrom :: forall x. ResultSet -> Rep ResultSet x
Prelude.Generic)

-- |
-- Create a value of 'ResultSet' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'headers', 'resultSet_headers' - List of headers for all the data cells in the block. The header
-- identifies the name and default format of the data cell. Data cells
-- appear in the same order in all rows as defined in the header. The names
-- and formats are not repeated in the rows. If a particular row does not
-- have a value for a data cell, a blank value is used.
--
-- For example, a task list that displays the task name, due date and
-- assigned person might have headers [ { \"name\": \"Task Name\"},
-- {\"name\": \"Due Date\", \"format\": \"DATE\"}, {\"name\": \"Assigned\",
-- \"format\": \"CONTACT\"} ]. Every row in the result will have the task
-- name as the first item, due date as the second item and assigned person
-- as the third item. If a particular task does not have a due date, that
-- row will still have a blank value in the second element and the assigned
-- person will still be in the third element.
--
-- 'rows', 'resultSet_rows' - List of rows returned by the request. Each row has a row Id and a list
-- of data cells in that row. The data cells will be present in the same
-- order as they are defined in the header.
newResultSet ::
  ResultSet
newResultSet :: ResultSet
newResultSet =
  ResultSet' :: [ColumnMetadata] -> [ResultRow] -> ResultSet
ResultSet'
    { $sel:headers:ResultSet' :: [ColumnMetadata]
headers = [ColumnMetadata]
forall a. Monoid a => a
Prelude.mempty,
      $sel:rows:ResultSet' :: [ResultRow]
rows = [ResultRow]
forall a. Monoid a => a
Prelude.mempty
    }

-- | List of headers for all the data cells in the block. The header
-- identifies the name and default format of the data cell. Data cells
-- appear in the same order in all rows as defined in the header. The names
-- and formats are not repeated in the rows. If a particular row does not
-- have a value for a data cell, a blank value is used.
--
-- For example, a task list that displays the task name, due date and
-- assigned person might have headers [ { \"name\": \"Task Name\"},
-- {\"name\": \"Due Date\", \"format\": \"DATE\"}, {\"name\": \"Assigned\",
-- \"format\": \"CONTACT\"} ]. Every row in the result will have the task
-- name as the first item, due date as the second item and assigned person
-- as the third item. If a particular task does not have a due date, that
-- row will still have a blank value in the second element and the assigned
-- person will still be in the third element.
resultSet_headers :: Lens.Lens' ResultSet [ColumnMetadata]
resultSet_headers :: ([ColumnMetadata] -> f [ColumnMetadata])
-> ResultSet -> f ResultSet
resultSet_headers = (ResultSet -> [ColumnMetadata])
-> (ResultSet -> [ColumnMetadata] -> ResultSet)
-> Lens ResultSet ResultSet [ColumnMetadata] [ColumnMetadata]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultSet' {[ColumnMetadata]
headers :: [ColumnMetadata]
$sel:headers:ResultSet' :: ResultSet -> [ColumnMetadata]
headers} -> [ColumnMetadata]
headers) (\s :: ResultSet
s@ResultSet' {} [ColumnMetadata]
a -> ResultSet
s {$sel:headers:ResultSet' :: [ColumnMetadata]
headers = [ColumnMetadata]
a} :: ResultSet) (([ColumnMetadata] -> f [ColumnMetadata])
 -> ResultSet -> f ResultSet)
-> (([ColumnMetadata] -> f [ColumnMetadata])
    -> [ColumnMetadata] -> f [ColumnMetadata])
-> ([ColumnMetadata] -> f [ColumnMetadata])
-> ResultSet
-> f ResultSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ColumnMetadata] -> f [ColumnMetadata])
-> [ColumnMetadata] -> f [ColumnMetadata]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | List of rows returned by the request. Each row has a row Id and a list
-- of data cells in that row. The data cells will be present in the same
-- order as they are defined in the header.
resultSet_rows :: Lens.Lens' ResultSet [ResultRow]
resultSet_rows :: ([ResultRow] -> f [ResultRow]) -> ResultSet -> f ResultSet
resultSet_rows = (ResultSet -> [ResultRow])
-> (ResultSet -> [ResultRow] -> ResultSet)
-> Lens ResultSet ResultSet [ResultRow] [ResultRow]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultSet' {[ResultRow]
rows :: [ResultRow]
$sel:rows:ResultSet' :: ResultSet -> [ResultRow]
rows} -> [ResultRow]
rows) (\s :: ResultSet
s@ResultSet' {} [ResultRow]
a -> ResultSet
s {$sel:rows:ResultSet' :: [ResultRow]
rows = [ResultRow]
a} :: ResultSet) (([ResultRow] -> f [ResultRow]) -> ResultSet -> f ResultSet)
-> (([ResultRow] -> f [ResultRow]) -> [ResultRow] -> f [ResultRow])
-> ([ResultRow] -> f [ResultRow])
-> ResultSet
-> f ResultSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ResultRow] -> f [ResultRow]) -> [ResultRow] -> f [ResultRow]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ResultSet where
  parseJSON :: Value -> Parser ResultSet
parseJSON =
    String -> (Object -> Parser ResultSet) -> Value -> Parser ResultSet
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResultSet"
      ( \Object
x ->
          [ColumnMetadata] -> [ResultRow] -> ResultSet
ResultSet'
            ([ColumnMetadata] -> [ResultRow] -> ResultSet)
-> Parser [ColumnMetadata] -> Parser ([ResultRow] -> ResultSet)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe [ColumnMetadata])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"headers" Parser (Maybe [ColumnMetadata])
-> [ColumnMetadata] -> Parser [ColumnMetadata]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ColumnMetadata]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([ResultRow] -> ResultSet)
-> Parser [ResultRow] -> Parser ResultSet
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [ResultRow])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"rows" Parser (Maybe [ResultRow]) -> [ResultRow] -> Parser [ResultRow]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ResultRow]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ResultSet

instance Prelude.NFData ResultSet