unit _WindowLastSeen;

interface

uses
  System.Classes, System.Contnrs, Winapi.Windows;

type
  TWindowLastSeenItem = class(TObject)
  private
    FHasChanged: Boolean;
    FLastSeenResolution: string;
    FHashedClassName: string;
    FLastSeen: TDateTime;
    procedure SetHasChanged(const Value: Boolean);
    procedure SetHashedClassName(const Value: string);
    procedure SetLastSeen(const Value: TDateTime);
    procedure SetLastSeenResolution(const Value: string);
  public
    property HashedClassName: string read FHashedClassName write SetHashedClassName;
    property HasChanged: Boolean read FHasChanged write SetHasChanged;
    property LastSeen: TDateTime read FLastSeen write SetLastSeen;
    property LastSeenResolution: string read FLastSeenResolution write SetLastSeenResolution;
  end;

  TWindowLastSeen = class(TObjectList)
  private
  protected
    function GetItem(Index: Integer): TWindowLastSeenItem;
    procedure SetItem(Index: Integer; AObject: TWindowLastSeenItem);
  public
    function Add(AObject: TWindowLastSeenItem): Integer;
    function GetItemByHashedClassName(const AHashedClassName: string): TWindowLastSeenItem;
    property Items[Index: Integer]: TWindowLastSeenItem read GetItem write SetItem;
  end;

implementation

{ TWindowListItem }

procedure TWindowLastSeenItem.SetHasChanged(const Value: Boolean);
begin
  FHasChanged := Value;
end;

procedure TWindowLastSeenItem.SetHashedClassName(const Value: string);
begin
  FHashedClassName := Value;
end;

procedure TWindowLastSeenItem.SetLastSeen(const Value: TDateTime);
begin
  FLastSeen := Value;
end;

procedure TWindowLastSeenItem.SetLastSeenResolution(const Value: string);
begin
  FLastSeenResolution := Value;
end;

{ TWindowLastSeen }

function TWindowLastSeen.Add(AObject: TWindowLastSeenItem): Integer;
begin
  Result := inherited Add(AObject);
end;

function TWindowLastSeen.GetItem(Index: Integer): TWindowLastSeenItem;
begin
  Result := TWindowLastSeenItem(inherited Items[Index]);
end;

function TWindowLastSeen.GetItemByHashedClassName(
  const AHashedClassName: string): TWindowLastSeenItem;
var
  i: Integer;
begin
  Result := nil;

  for i := 0 to Count - 1 do
  begin
    if AHashedClassName = Items[i].HashedClassName then
    begin
      Result := Items[i];
    end;
  end;
end;

procedure TWindowLastSeen.SetItem(Index: Integer; AObject: TWindowLastSeenItem);
begin
  inherited Items[Index] := AObject;
end;

end.
