unit Azure.CognitiveServices.ImageModeration.JSON;

interface

uses
  System.JSON,
  Azure.CognitiveServices.ImageModeration.Types;

type

  TAcsImageModerationJSON = class
  public
    class function ToJSON(const AData: TAcsImageModerationRequest): TJSONObject;
    class procedure Parse(const AObject: TJSONObject; var AData: TAcsImageModerationResponse); overload;
    class procedure Parse(const AObject: TJSONObject; var AData: TAcsImageModerationStatus); overload;
  end;

implementation

class procedure TAcsImageModerationJSON.Parse(const AObject: TJSONObject;
  var AData: TAcsImageModerationResponse);
begin
  AData.AdultClassificationScore := AObject.GetValue<Double>('AdultClassificationScore');
  AData.IsImageAdultClassified := AObject.GetValue<Boolean>('IsImageAdultClassified');
  AData.RacyClassificationScore := AObject.GetValue<Double>('RacyClassificationScore');
  AData.IsImageRacyClassified := AObject.GetValue<Boolean>('IsImageRacyClassified');
  AData.Result := AObject.GetValue<Boolean>('Result');
  Parse(TJSONObject(AObject.GetValue('Status')), AData.Status);
  AData.TrackingId := AObject.GetValue<string>('TrackingId');
end;

class procedure TAcsImageModerationJSON.Parse(const AObject: TJSONObject;
  var AData: TAcsImageModerationStatus);
begin
  AData.Code := AObject.GetValue<Integer>('Code');
  AData.Description := AObject.GetValue<string>('Description');
end;

class function TAcsImageModerationJSON.ToJSON(
  const AData: TAcsImageModerationRequest): TJSONObject;
begin
  Result := TJSONObject.Create;
  if Length(AData.ImageUrl) <= 0 then
    Exit;
  Result.AddPair('DataRepresentation', 'URL');
  Result.AddPair('Value', AData.ImageUrl);
end;

end.
