66
77module VVA.API.SyncAiResponseType where
88
9- import Data.Maybe (fromMaybe )
10- import GHC.Generics (Generic )
11- import Data.Text (Text )
9+ import Data.Maybe (fromMaybe )
10+ import GHC.Generics (Generic )
11+ import Data.Text (Text )
1212import qualified Data.Text (stripPrefix )
13- import Data.Aeson
13+ import Data.Aeson
1414import qualified Data.Aeson.Types as Aeson
15- import Data.Aeson.Types (Parser )
15+ import Data.Aeson.Types (Parser )
1616import qualified Data.Aeson.Key as Key
17- import Data.OpenApi (ToSchema )
18- import Control.Applicative ((<|>) )
17+ import Data.OpenApi (ToSchema )
18+ import Control.Applicative ((<|>) )
19+ import Data.Scientific
1920
2021-- Helper: safe lookup for Maybe Value
2122(.::?) :: Maybe Value -> Text -> Parser (Maybe Value )
@@ -37,46 +38,48 @@ instance ToJSON TextOrValue where
3738 toJSON (TextOrValue t) = String t
3839
3940data SearchAiResponse = SearchAiResponse
40- { data_ :: Maybe [DRepData ]
41+ { elements :: Maybe [DRepData ]
4142 , meta :: Meta
4243 , pagination :: Pagination
4344 } deriving (Show , Generic , ToSchema )
4445
4546instance FromJSON SearchAiResponse where
4647 parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = fixData }
47- where fixData " data_ " = " data"
48+ where fixData " elements " = " data"
4849 fixData other = other
4950instance ToJSON SearchAiResponse where
5051 toJSON = genericToJSON defaultOptions { fieldLabelModifier = fixData }
51- where fixData " data_ " = " data"
52+ where fixData " elements " = " data"
5253 fixData other = other
5354
5455data DRepData = DRepData
55- { drepId :: Text
56- -- Missing:
57- -- , dRepHash :: Text
58- -- , view :: Text
59- -- , isScriptBased :: Bool
60- , url :: Maybe Text
61- -- Missing:
62- -- , dataHash :: Maybe Text
63- -- , deposit :: Integer
64- -- , votingPower :: Double -- We might need to multiply this by 1e6 to get the actual voting power + Int
65- , status :: Text
66- -- Missing:
67- -- , type :: DRepType
68- -- , latestTxHash :: Maybe Text
56+ { deposit :: Scientific
57+ , drepId :: Text
58+ , givenName :: Maybe Text
59+ , identityRefs :: [Reference ]
60+ , imageHash :: Maybe TextOrValue
61+ , imageUrl :: Maybe TextOrValue
62+ , isScriptBased :: Bool
6963 -- , latestRegistrationDate :: UTCTime
70- -- , metadataError :: Maybe Text
71- , paymentAddress :: Maybe TextOrValue
72- , givenName :: Maybe Text
73- , objectives :: Maybe Text
74- , motivations :: Maybe Text
75- , qualifications :: Maybe TextOrValue
76- , imageUrl :: Maybe TextOrValue
77- , imageHash :: Maybe TextOrValue
78- , linkReferences :: [Reference ]
79- , identityReferences :: [Reference ]
64+ , latestRegistrationDate :: Maybe Text
65+ , latestTxHash :: Maybe Text
66+ , linkReferences :: [Reference ]
67+ , metadataError :: Maybe Text
68+ , metadataHash :: Maybe Text
69+ , motivations :: Maybe Text
70+ , objectives :: Maybe Text
71+ , paymentAddress :: Maybe TextOrValue
72+ , qualifications :: Maybe TextOrValue
73+ -- , status :: DRepStatus
74+ , status :: Maybe Text
75+ -- , type :: DRepType
76+ , type_ :: Maybe Text
77+ , url :: Maybe Text
78+ , view :: Text
79+ , votingPower :: Maybe Integer -- We might need to multiply this by 1e6 to get the actual voting power + Int
80+ -- THOSE ARE WEIRD FIELDS, NOT USED FOR NOW
81+ -- , drepHash :: Text
82+ -- , dataHash :: Maybe Text
8083 } deriving (Show , Generic , ToSchema , ToJSON )
8184
8285instance FromJSON DRepData where
@@ -87,9 +90,8 @@ instance FromJSON DRepData where
8790 objectives <- v .: " objectives"
8891 status <- v .: " status"
8992 url <- v .:? " url"
90- -- votingPower <- (v .: "votingPower" <|> (v .: "metrics" >>= (.: "votingPower")))
9193
92- --
94+ -- dRep data manipulation:
9395 mMeta <- v .:? " metadata"
9496 mJsonMeta <- mMeta .::? " json_metadata"
9597 mBody <- mJsonMeta .::? " body"
@@ -144,9 +146,21 @@ instance FromJSON DRepData where
144146 , filter (\ ref -> refType ref == Just " Identity" ) refs
145147 )
146148
149+ -- Placeholders for fields not yet implemented
150+ deposit <- pure 123456789
151+ latestRegistrationDate <- pure (Just " 2023-10-01T00:00:00Z" )
152+ latestTxHash <- pure Nothing
153+ isScriptBased <- pure False
154+ metadataError <- pure Nothing
155+ metadataHash <- pure Nothing
156+ type_ <- pure (Just " DRep" )
157+ view <- pure " https://example.com/view"
158+ votingPower <- pure (Just 100 )
159+
147160 pure $ DRepData
148- drepId motivations givenName objectives status url -- votingPower
149- imageUrl imageHash paymentAddress qualifications linkRefs identityRefs
161+ deposit drepId givenName identityRefs imageHash imageUrl isScriptBased latestRegistrationDate
162+ latestTxHash linkRefs metadataError metadataHash motivations objectives paymentAddress
163+ qualifications status type_ url view votingPower
150164
151165data Reference = Reference
152166 { refType :: Maybe Text -- "@type"
0 commit comments