{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.HoneyCode.Types.ResultSet where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.HoneyCode.Types.ColumnMetadata
import Amazonka.HoneyCode.Types.ResultRow
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
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
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. 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'
    { $sel:headers:ResultSet' :: [ColumnMetadata]
headers = forall a. Monoid a => a
Prelude.mempty,
      $sel:rows:ResultSet' :: [ResultRow]
rows = 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 :: Lens' ResultSet [ColumnMetadata]
resultSet_headers = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' ResultSet [ResultRow]
resultSet_rows = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ResultSet where
  hashWithSalt :: Int -> ResultSet -> Int
hashWithSalt Int
_salt ResultSet' {[ColumnMetadata]
[ResultRow]
rows :: [ResultRow]
headers :: [ColumnMetadata]
$sel:rows:ResultSet' :: ResultSet -> [ResultRow]
$sel:headers:ResultSet' :: ResultSet -> [ColumnMetadata]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ColumnMetadata]
headers
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ResultRow]
rows

instance Prelude.NFData ResultSet where
  rnf :: ResultSet -> ()
rnf ResultSet' {[ColumnMetadata]
[ResultRow]
rows :: [ResultRow]
headers :: [ColumnMetadata]
$sel:rows:ResultSet' :: ResultSet -> [ResultRow]
$sel:headers:ResultSet' :: ResultSet -> [ColumnMetadata]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [ColumnMetadata]
headers seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ResultRow]
rows