unit XData.Payload.Reader;

interface

uses
  Generics.Collections, Classes,
  Bcl.Collections,
  Bcl.Json.Converters,
  XData.Json.Solver,
  XData.Model.Classes,
  XData.Service.Common;

type
  IPayloadReader = interface
  ['{5A2D0D75-87A8-4FBC-829C-05372C88C8C7}']
    function ContentType: string;
  end;

  TXDataPayloadReader = class abstract(TInterfacedObject, IPayloadReader)
  strict private
    FStream: TStream;
    FModel: TXDataModel;
    FBaseUrl: string;
//    FVersion: TXDataVersion;
    FSolver: IJsonReferenceSolver;
    FManagedObjects: THashSet<TObject>;
  strict protected
    function ContentType: string; virtual; abstract;
    property Solver: IJsonReferenceSolver read FSolver;
  public
    constructor Create(const AStream: TStream; const AModel: TXDataModel; const ABaseUrl: string;
      ASolver: IJsonReferenceSolver; AManagedObjects: THashSet<TObject>);
    property Stream: TStream read FStream;
    property Model: TXDataModel read FModel;
    property BaseUrl: string read FBaseUrl;
//    property Version: TXDataVersion read FVersion;
    property ManagedObjects: THashSet<TObject> read FManagedObjects;
  end;

  IEntityCollectionReader = interface(IPayloadReader)
  ['{5D56562B-EF4C-440F-BDF9-5BFD4FA02229}']
//    procedure Start(const ABaseType: TXDataEntityType);
//    procedure SerializeItem(const AObject: TObject);
//    procedure Finish;
  end;

  IEntityReader = interface(IPayloadReader)
  ['{5D22FB8F-9CB8-4DDE-97B8-99B5D476DD12}']
    procedure ReadEntity(Target: TObject);
    function CreateEntity(const AEntityType: TXDataEntityType): TObject;
    procedure SetUnknownMemberHandling(Value: TUnknownMemberHandling);
  end;

  IPropertyReader = interface(IPayloadReader)
  ['{A50FE220-FA2A-4B4F-9388-8F48B9B21DA3}']
    procedure ReadProperty(const AObject: TObject; const AProp: TXDataSimpleProperty);
  end;

  IParamsReader = interface(IPayloadReader)
  ['{75C30793-9A14-455E-8A43-5ED9912D24A4}']
    procedure ReadParams(const Action: TXDataAction; Params: IXDataActionParams);
    procedure SetUnknownMemberHandling(Value: TUnknownMemberHandling);
  end;

  IErrorReader = interface(IPayloadReader)
  ['{DCE49EBB-405B-4C6F-9A9B-D5EFE18F3AF5}']
    procedure ReadError(var ErrorCode, ErrorMessage: string);
  end;

implementation

{ TXDataPayloadReader }

constructor TXDataPayloadReader.Create(const AStream: TStream; const AModel: TXDataModel;
  const ABaseUrl: string; ASolver: IJsonReferenceSolver; AManagedObjects: THashSet<TObject>);
begin
  FStream := AStream;
  FModel := AModel;
  FBaseUrl := ABaseUrl;
  FSolver := ASolver;
  FManagedObjects := AManagedObjects;
end;

end.
