unit XData.Service.Internal;

interface

uses
  System.Rtti, System.TypInfo, Generics.Collections,
  XData.Model.Classes,
  XData.Service.Common,
  XData.Sys.Exceptions;

type
  TXDataActionParams = class(TInterfacedObject, IXDataActionParams)
  strict private
    FParams: TDictionary<string, TValue>;
  public
    constructor Create;
    destructor Destroy; override;
    function GetValue(const ParamName: string): TValue;
    procedure SetValue(const ParamName: string; const Value: TValue);
    function HasValue(const ParamName: string): boolean;
    function ParamNames: TEnumerable<string>;
  end;

implementation

uses
  System.SysUtils;

{ TXDataParamValues }

constructor TXDataActionParams.Create;
begin
  FParams := TDictionary<string, TValue>.Create;
end;

destructor TXDataActionParams.Destroy;
begin
  FParams.Free;
  inherited;
end;

function TXDataActionParams.GetValue(const ParamName: string): TValue;
begin
  if not FParams.TryGetValue(LowerCase(ParamName), Result) then
    Result := TValue.Empty;
end;

function TXDataActionParams.HasValue(const ParamName: string): boolean;
begin
  Result := FParams.ContainsKey(LowerCase(ParamName));
end;

function TXDataActionParams.ParamNames: TEnumerable<string>;
begin
  Result := FParams.Keys;
end;

procedure TXDataActionParams.SetValue(const ParamName: string; const Value: TValue);
begin
  FParams.AddOrSetValue(LowerCase(ParamName), Value);
end;

end.
