content: -- Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
  -- SPDX-License-Identifier: Apache-2.0
  
  {-# LANGUAGE DuplicateRecordFields #-}
  
  -- These types offer the following benefits over the LowLevel types
  --
  -- (1) These types are human curated and intended for human consumption.
  --     (The lowlevel types are generated by compile-proto,
  --      and have verbose record-field and constructor names.)
  -- (2) These types are stronger:
  --      distinguishing various identifier classes, instead of everywhere being `Text`.
  -- (3) These types capture required-field invariants.
  -- (4) These types form a barrier against changes to names & representation in the .proto files.
  
  module DA.Ledger.Types( -- High Level types for communication over Ledger API
      Party(..),
      Timestamp(..),
      -- TODO[SW] Can this be deleted?
      UserId(..),
      PackageId(..),
      ParticipantId(..),
      ) where
  
  import qualified Data.Aeson as A
  import Data.Text.Lazy (Text)
  import Prelude hiding(Enum)
  import qualified Data.Text.Lazy as Text(unpack)
  
  data Timestamp = Timestamp
      { seconds :: Int
      , nanos   :: Int
      }
      deriving (Eq,Ord,Show)
  
  newtype UserId = UserId { unUserId :: Text } deriving (Eq,Ord,Show)
  instance A.FromJSON UserId where
    parseJSON v = UserId <$> A.parseJSON v
  
  newtype ParticipantId = ParticipantId { unParticipantId :: Text} deriving (Eq,Ord,Show)
  instance A.FromJSON ParticipantId where
    parseJSON v = ParticipantId <$> A.parseJSON v
  
  newtype PackageId = PackageId { unPackageId :: Text } deriving (Eq,Ord,Show)
  
  newtype Party = Party { unParty :: Text } deriving (Eq,Ord)
  instance Show Party where show p = "'" <> Text.unpack (unParty p) <> "'"
  instance A.FromJSON Party where
    parseJSON v = Party <$> A.parseJSON v
  