unit uClasse.Json.confirmacao;

interface

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

type
  TProductsDTO = class
  private
    FDescription: string;
    FEan:         String;
    FQuantity:    Integer;
  published
    property Description: string read FDescription write FDescription;
    property Ean:         String read FEan write FEan;
    property Quantity:    Integer read FQuantity write FQuantity;
  end;

  TSales_ConfirmPreAuthorizedSaleDTO = class
  private
    FAuthorizationID: Integer;
    FCardBalance:     Double;
    FCardPaidValue:   Double;
    FCreatedAt:       TDateTime;
    FMoneyPaidValue:  Double;
    [JSONName('products')]
    FProductsArray: TArray<TProductsDTO>;
    [GenericListReflect]
    FProducts:      TObjectList<TProductsDTO>;
    FReceipt:       string;
    FStatus:        string;
    FStatusCode:    Integer;
    FStatusMessage: string;
    FTotalValue:    Double;
    function GetProducts: TObjectList<TProductsDTO>;
  published
    property AuthorizationID: Integer read FAuthorizationID write FAuthorizationID;
    property CardBalance:     Double read FCardBalance write FCardBalance;
    property CardPaidValue:   Double read FCardPaidValue write FCardPaidValue;
    property CreatedAt:       TDateTime read FCreatedAt write FCreatedAt;
    property MoneyPaidValue:  Double read FMoneyPaidValue write FMoneyPaidValue;
    property Products:        TObjectList<TProductsDTO> read GetProducts;
    property Receipt:         string read FReceipt write FReceipt;
    property Status:          string read FStatus write FStatus;
    property StatusCode:      Integer read FStatusCode write FStatusCode;
    property StatusMessage:   string read FStatusMessage write FStatusMessage;
    property TotalValue:      Double read FTotalValue write FTotalValue;
    destructor Destroy; override;
  end;

  TDataDTO = class
  private
    FSales_ConfirmPreAuthorizedSale: TSales_ConfirmPreAuthorizedSaleDTO;
  published
    property Sales_ConfirmPreAuthorizedSale: TSales_ConfirmPreAuthorizedSaleDTO read FSales_ConfirmPreAuthorizedSale
      write FSales_ConfirmPreAuthorizedSale;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  TRootDTO = class(TJsonDTO)
  private
    FData: TDataDTO;
  published
    property Data: TDataDTO read FData write FData;
  public
    constructor Create; override;
    destructor Destroy; override;
  end;

implementation

{ TSales_ConfirmPreAuthorizedSaleDTO }

destructor TSales_ConfirmPreAuthorizedSaleDTO.Destroy;
begin
  GetProducts.Free;
  inherited;
end;

function TSales_ConfirmPreAuthorizedSaleDTO.GetProducts: TObjectList<TProductsDTO>;
begin
  if not Assigned(FProducts) then
  begin
    FProducts := TObjectList<TProductsDTO>.Create;
    FProducts.AddRange(FProductsArray);
  end;
  Result := FProducts;
end;

{ TDataDTO }

constructor TDataDTO.Create;
begin
  inherited;
  FSales_ConfirmPreAuthorizedSale := TSales_ConfirmPreAuthorizedSaleDTO.Create;
end;

destructor TDataDTO.Destroy;
begin
  FSales_ConfirmPreAuthorizedSale.Free;
  inherited;
end;

{ TRootDTO }

constructor TRootDTO.Create;
begin
  inherited;
  FData := TDataDTO.Create;
end;

destructor TRootDTO.Destroy;
begin
  FData.Free;
  inherited;
end;

end.
