unit Sphinx.Extensions;

interface

uses
  System.SysUtils,
  Generics.Collections,
  Aurelius.Mapping.Attributes,
  Aurelius.Types.Blob,
  Aurelius.Types.DynamicProperties,
  Bcl.Types.Nullable,
  Aurelius.Types.Proxy,
  Aurelius.Events.Manager,
  XData.Security.Attributes,
  Sphinx.Entities,
  Sphinx.Consts,
  App.Enumerations;

{$SCOPEDENUMS ON}

type

{$RTTI EXPLICIT METHODS([vcProtected..vcPublished])}

  [Entity]
  [AutoMapping]
  [DiscriminatorValue('APU')]
  [Model(cSphinxModelName)]
  [Sequence('SEQ_USER', 1000, 1)]
  TUserEx = class(TUser)
  private
    FInternalId: NullableInteger;
    FUserStatus: TUserStatus;
    FUserCategory: TUserCategory;
    [Column('LAST_NAME', [], 25)]
    FLastName: NullableString;
    [Column('FIRST_NAME', [], 25)]
    FFirstName: NullableString;
  protected
    {$IFDEF APP_SERVER}
    [OnInserting]
    procedure OnInserting(Args: TInsertingArgs);
    {$ENDIF}
  public
    property InternalId: NullableInteger read FInternalId write FInternalId;
    property UserStatus: TUserStatus read FUserStatus write FUserStatus;
    property UserCategory: TUserCategory read FUserCategory write FUserCategory;
    property FirstName: NullableString read FFirstName write FFirstName;
    property LastName: NullableString read FLastName write FLastName;
  end;

implementation

{$IFDEF APP_SERVER}
uses
  Aurelius.Engine.ObjectManager;

procedure TUserEx.OnInserting(Args: TInsertingArgs);
var
  lUser: TUserEx;
begin
  lUser := TUserEx(Args.Entity);
  lUser.UserStatus := TUserStatus.Active;
  lUser.UserCategory := TUserCategory.User;
end;

initialization
  RegisterEntity(TUserEx);
{$ENDIF}

end.
