unit XData.Payload.Json.Factory;

interface

uses
  Classes,
  Bcl.Collections,
  XData.Payload.Factory,
  XData.Payload.Reader,
  XData.Payload.Writer;

type
  TXDataPayloadJsonFactory = class(TXDataPayloadFactory)
  public
    function CreateEntityCollectionWriter(const Stream: TStream): IEntityCollectionWriter; override;
    function CreateEntityWriter(const Stream: TStream): IEntityWriter; override;
    function CreateServiceDocumentWriter(const Stream: TStream): IServiceDocumentWriter; override;
    function CreateErrorWriter(const Stream: TStream): IErrorWriter; override;
    function CreatePropertyWriter(const Stream: TStream): IPropertyWriter; override;
    function CreateResultWriter(const Stream: TStream): IResultWriter; override;

    function CreateEntityReader(const Stream: TStream; Solver: IJsonReferenceSolver; ManagedObjects: THashSet<TObject>): IEntityReader; override;
    function CreateParamsReader(const Stream: TStream; Solver: IJsonReferenceSolver; ManagedObjects: THashSet<TObject>): IParamsReader; override;
    function CreateErrorReader(const Stream: TStream): IErrorReader; override;
  end;

implementation

uses
  XData.Payload.Json.Reader,
  XData.Payload.Json.Writer;

{ TXDataPayloadJsonFactory }

function TXDataPayloadJsonFactory.CreateEntityCollectionWriter(const Stream: TStream): IEntityCollectionWriter;
begin
  Result := TJsonEntityCollectionWriter.Create(Stream, Model, BaseUrl);
end;

function TXDataPayloadJsonFactory.CreateEntityReader(const Stream: TStream;
  Solver: IJsonReferenceSolver; ManagedObjects: THashSet<TObject>): IEntityReader;
begin
  Result := TJsonEntityReader.Create(Stream, Model, BaseUrl, Solver, ManagedObjects);
end;

function TXDataPayloadJsonFactory.CreateEntityWriter(const Stream: TStream): IEntityWriter;
begin
  Result := TJsonEntityWriter.Create(Stream, Model, BaseUrl);
end;

function TXDataPayloadJsonFactory.CreateErrorReader(const Stream: TStream): IErrorReader;
begin
  Result := TJsonErrorReader.Create(Stream, Model, BaseUrl, nil, nil);
end;

function TXDataPayloadJsonFactory.CreateErrorWriter(const Stream: TStream): IErrorWriter;
begin
  Result := TJsonErrorWriter.Create(Stream, Model, BaseUrl);
end;

function TXDataPayloadJsonFactory.CreateParamsReader(const Stream: TStream;
  Solver: IJsonReferenceSolver; ManagedObjects: THashSet<TObject>): IParamsReader;
begin
  Result := TJsonParamsReader.Create(Stream, Model, BaseUrl, Solver, ManagedObjects);
end;

function TXDataPayloadJsonFactory.CreatePropertyWriter(const Stream: TStream): IPropertyWriter;
begin
  Result := TJsonPropertyWriter.Create(Stream, Model, BaseUrl);
end;

function TXDataPayloadJsonFactory.CreateResultWriter(const Stream: TStream): IResultWriter;
begin
  Result := TJsonResultWriter.Create(Stream, Model, BaseUrl);
end;

function TXDataPayloadJsonFactory.CreateServiceDocumentWriter(const Stream: TStream): IServiceDocumentWriter;
begin
  Result := TJsonServiceDocumentWriter.Create(Stream, Model, BaseUrl);
end;

end.
