unit XData.Security.Interfaces;

interface

uses
  System.SysUtils,
  System.Generics.Collections,
  System.Rtti,
  Sparkle.Security;

type
  IAuthorizationContext = interface
  ['{D3B11F63-3122-46C0-BFA9-4F9EE0146B48}']
    function GetUser: IUserIdentity;
    property User: IUserIdentity read GetUser;
  end;

  IRequirementResult = interface
  ['{FE138E37-1216-4DD4-9998-BE9E986BF19F}']
    function GetSucceeded: Boolean;
    property Succeeded: Boolean read GetSucceeded;
  end;

  IAuthorizationRequirement = interface
  ['{610A228B-7849-42FA-B929-87BE9AEFED37}']
    function Check(Context: IAuthorizationContext): IRequirementResult;
  end;

  TRequirementResult = class(TInterfacedObject, IRequirementResult)
  strict private
    FSucceeded: Boolean;
    function GetSucceeded: Boolean;
  public
    class function Success: IRequirementResult;
    class function Failed: IRequirementResult;
    constructor Create(ASucceeded: Boolean); reintroduce;
    property Succeeded: Boolean read GetSucceeded;
  end;

implementation

{ TRequirementResult }

constructor TRequirementResult.Create(ASucceeded: Boolean);
begin
  FSucceeded := ASucceeded;
end;

class function TRequirementResult.Failed: IRequirementResult;
begin
  Result := TRequirementResult.Create(False);
end;

function TRequirementResult.GetSucceeded: Boolean;
begin
  Result := FSucceeded;
end;

class function TRequirementResult.Success: IRequirementResult;
begin
  Result := TRequirementResult.Create(True);
end;

end.
