unit uClasse.Json.Recuperacao;

interface

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

// {$M+}

type
  TPrescriberDTO = class
  private
    FCouncil:        string;
    FRegisterNumber: Integer;
    FStateAbbr:      string;
  published
    property Council:        string read FCouncil write FCouncil;
    property RegisterNumber: Integer read FRegisterNumber write FRegisterNumber;
    property StateAbbr:      string read FStateAbbr write FStateAbbr;
  end;

  TMedicalPrescriptionDTO = class
  private
    FDate:       TDateTime;
    FPrescriber: TPrescriberDTO;
    FQuantity:   Integer;
  published
    property Date:       TDateTime read FDate write FDate;
    property Prescriber: TPrescriberDTO read FPrescriber write FPrescriber;
    property Quantity:   Integer read FQuantity write FQuantity;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  TProductsDTO = class
  private
    FDescription:         string;
    FEan:                 string;
    FMaxConsumerPrice:    Double;
    FMedicalPrescription: TMedicalPrescriptionDTO;
    FQuantity:            Integer;
    FStatus:              string;
    FStatusCode:          Integer;
    FUnitPrice:           Double;
  published
    property Description:         string read FDescription write FDescription;
    property Ean:                 string read FEan write FEan;
    property MaxConsumerPrice:    Double read FMaxConsumerPrice write FMaxConsumerPrice;
    property MedicalPrescription: TMedicalPrescriptionDTO read FMedicalPrescription write FMedicalPrescription;
    property Quantity:            Integer read FQuantity write FQuantity;
    property Status:              string read FStatus write FStatus;
    property StatusCode:          Integer read FStatusCode write FStatusCode;
    property UnitPrice:           Double read FUnitPrice write FUnitPrice;
  public
    constructor Create;
    destructor Destroy; override;
  end;

  TSales_TransactionDTO = class
  private
    FAuthorizationID: Integer;
    FCardPaidValue:   Double;
    FCreatedAt:       TDateTime;
    FMoneyPaidValue:  Double;
    [JSONName('products')]
    FProductsArray: TArray<TProductsDTO>;
    [GenericListReflect]
    FProducts:   TObjectList<TProductsDTO>;
    FTotalValue: Double;
    function GetProducts: TObjectList<TProductsDTO>;
  published
    property AuthorizationID: Integer read FAuthorizationID write FAuthorizationID;
    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 TotalValue:      Double read FTotalValue write FTotalValue;
    destructor Destroy; override;
  end;

  TDataDTO = class
  private
    FSales_Transaction: TSales_TransactionDTO;
  published
    property Sales_Transaction: TSales_TransactionDTO read FSales_Transaction write FSales_Transaction;
  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

{ TMedicalPrescriptionDTO }

constructor TMedicalPrescriptionDTO.Create;
begin
  inherited;
  FPrescriber := TPrescriberDTO.Create;
end;

destructor TMedicalPrescriptionDTO.Destroy;
begin
  FPrescriber.Free;
  inherited;
end;

{ TProductsDTO }

constructor TProductsDTO.Create;
begin
  inherited;
  FMedicalPrescription := TMedicalPrescriptionDTO.Create;
end;

destructor TProductsDTO.Destroy;
begin
  FMedicalPrescription.Free;
  inherited;
end;

{ TSales_TransactionDTO }

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

function TSales_TransactionDTO.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_Transaction := TSales_TransactionDTO.Create;
end;

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

{ TRootDTO }

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

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

end.
