unit Aurelius.Plugin.Database;

interface

uses
  SysUtils, Classes, Generics.Collections;

type
  IPluginTable = interface;

  IPluginDatabase = interface
    ['{62D03881-A72B-490E-9F71-0ECA0C1705E6}']
    function TableCount: Integer;
    function GetTable(Index: Integer): IPluginTable;
  end;

  IPluginTable = interface
    ['{322E2F23-DE78-48A3-A04B-595DC8FD7295}']
    function GetId: Integer;
    function GetName: WideString;
    property Id: Integer read GetId;
    property Name: WideString read GetName;
  end;

  TPluginDatabase = class(TInterfacedObject, IPluginDatabase)
  strict private
    FTables: TList<IPluginTable>;
  public
    constructor Create(ATables: TArray<IPluginTable>);
    destructor Destroy; override;
    function TableCount: Integer;
    function GetTable(Index: Integer): IPluginTable;
  end;

  TPluginTable = class(TInterfacedObject, IPluginTable)
  strict private
    FId: Integer;
    FName: WideString;
    function GetId: Integer;
    function GetName: WideString;
  public
    constructor Create(AId: integer; AName: WideString);
  end;

implementation


{ TPluginDatabase }

constructor TPluginDatabase.Create(ATables: TArray<IPluginTable>);
begin
  FTables := TList<IPluginTable>.Create;
  FTables.AddRange(ATables);
end;

destructor TPluginDatabase.Destroy;
begin
  FTables.Free;
  inherited;
end;

function TPluginDatabase.GetTable(Index: Integer): IPluginTable;
begin
  Result := FTables[Index];
end;

function TPluginDatabase.TableCount: Integer;
begin
  Result := FTables.Count;
end;

{ TPluginTable }

constructor TPluginTable.Create(AId: integer; AName: WideString);
begin
  FId := AId;
  FName := AName;
end;

function TPluginTable.GetId: Integer;
begin
  Result := FId;
end;

function TPluginTable.GetName: WideString;
begin
  Result := FName;
end;

end.
