unit BaseRequest;

interface

uses
  Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;

{$M+}

type
  TRequest = class(TJsonDTO)
  private
    [JSONName('device_id')]
    FDeviceId: string;
    FRequestId: string;
    FSessionId: string;
  published
    property DeviceId: string read FDeviceId write FDeviceId;
    property RequestId: string read FRequestId write FRequestId;
    property SessionId: string read FSessionId write FSessionId;
    procedure FromJson(aValue: string);
  end;

  TBaseRequest = class(TJsonDTO)
  private
    [JSONName('request'), JSONMarshalled(False)]
    FRequestArray: TArray<TRequest>;
    [GenericListReflect]
    FRequest: TObjectList<TRequest>;
    function GetRequest: TObjectList<TRequest>;
  protected
    function GetAsJson: string; override;
    //procedure SetAsJson(aValue: string); virtual;
  published
    property Request: TObjectList<TRequest> read GetRequest;
    procedure FromJson(aValue: string);

  public
    destructor Destroy; override;

  end;

implementation

procedure TRequest.FromJson(aValue: string);
 begin
  TRequest(Self).SetAsJson(aValue);
 end;

procedure TBaseRequest.FromJson(aValue: string);
 begin
  TBaseRequest(Self).SetAsJson(aValue);
 end;

{ TBaseRequest }


destructor TBaseRequest.Destroy;
begin
  GetRequest.Free;
  inherited;
end;

function TBaseRequest.GetRequest: TObjectList<TRequest>;
begin
  Result := ObjectList<TRequest>(FRequest, FRequestArray);
end;

function TBaseRequest.GetAsJson: string;
begin
  RefreshArray<TRequest>(FRequest, FRequestArray);
  Result := inherited;
end;

end.
