unit XData.XmlDoc;

interface

uses
  Generics.Collections, SysUtils;

type
  TXmlDocNotesItem = class
  private
    FName: string;
    FContent: string;
  public
    constructor Create(const AName, AContent: string);
    property Name: string read FName write FName;
    property Content: string read FContent write FContent;
  end;

  TXmlDocNotes = class
  private
    FSummary: string;
    FRemarks: string;
    FParams: TList<TXmlDocNotesItem>;
    FSwaggerItems: TList<TXmlDocNotesItem>;
  public
    constructor Create;
    destructor Destroy; override;
    function ParamContent(const ParamName: string): string;
    function SwaggerContent(const Name: string): string;
    property Summary: string read FSummary write FSummary;
    property Remarks: string read FRemarks write FRemarks;
    property Params: TList<TXmlDocNotesItem> read FParams;
    property SwaggerItems: TList<TXmlDocNotesItem> read FSwaggerItems;
  end;

  TXmlDocMethod = class
  private
    FName: string;
    FNotes: TXmlDocNotes;
  public
    constructor Create;
    destructor Destroy; override;
    property Name: string read FName write FName;
    property Notes: TXmlDocNotes read FNotes;
  end;

  TXmlDocInterface = class
  private
    FName: string;
    FMethods: TList<TXmlDocMethod>;
    FNotes: TXmlDocNotes;
  public
    constructor Create;
    destructor Destroy; override;
    function MethodByName(const Name: string): TXmlDocMethod;
    property Name: string read FName write FName;
    property Methods: TList<TXmlDocMethod> read FMethods;
    property Notes: TXmlDocNotes read FNotes;
  end;

  TXmlDocMember = class
  private
    FName: string;
    FNotes: TXmlDocNotes;
  public
    constructor Create;
    destructor Destroy; override;
    property Name: string read FName write FName;
    property Notes: TXmlDocNotes read FNotes;
  end;

  TXmlDocClass = class
  private
    FName: string;
    FMembers: TList<TXmlDocMember>;
    FNotes: TXmlDocNotes;
  public
    constructor Create;
    destructor Destroy; override;
    function MemberByName(const Name: string): TXmlDocMember;
    property Name: string read FName write FName;
    property Members: TList<TXmlDocMember> read FMembers;
    property Notes: TXmlDocNotes read FNotes;
  end;

  TXmlDocUnit = class
  private
    FName: string;
    FInterfaces: TList<TXmlDocInterface>;
    FClasses: TList<TXmlDocClass>;
  public
    constructor Create;
    destructor Destroy; override;
    property Name: string read FName write FName;
    function InterfaceByName(const Name: string): TXmlDocInterface;
    property Interfaces: TList<TXmlDocInterface> read FInterfaces;
    function ClassByName(const Name: string): TXmlDocClass;
    property Classes: TList<TXmlDocClass> read FClasses;
  end;

  TXmlDocInfo = class
  private
    FUnits: TList<TXmlDocUnit>;
  public
    constructor Create;
    destructor Destroy; override;
    function UnitByName(const Name: string): TXmlDocUnit;
    property Units: TList<TXmlDocUnit> read FUnits;
  end;

implementation

{ TXmlDocUnit }

function TXmlDocUnit.ClassByName(const Name: string): TXmlDocClass;
var
  I: Integer;
begin
  for I := 0 to Classes.Count - 1 do
    if SameText(Classes[I].Name, Name) then
      Exit(Classes[I]);
  Result := nil;
end;

constructor TXmlDocUnit.Create;
begin
  inherited Create;
  FInterfaces := TObjectList<TXmlDocInterface>.Create;
  FClasses := TObjectList<TXmlDocClass>.Create;
end;

destructor TXmlDocUnit.Destroy;
begin
  FInterfaces.Free;
  FClasses.Free;
  inherited;
end;

function TXmlDocUnit.InterfaceByName(const Name: string): TXmlDocInterface;
var
  I: Integer;
begin
  for I := 0 to Interfaces.Count - 1 do
    if SameText(Interfaces[I].Name, Name) then
      Exit(Interfaces[I]);
  Result := nil;
end;

{ TXmlDocInterface }

constructor TXmlDocInterface.Create;
begin
  inherited Create;
  FMethods := TObjectList<TXmlDocMethod>.Create;
  FNotes := TXmlDocNotes.Create;
end;

destructor TXmlDocInterface.Destroy;
begin
  FMethods.Free;
  FNotes.Free;
  inherited;
end;

function TXmlDocInterface.MethodByName(const Name: string): TXmlDocMethod;
var
  I: Integer;
begin
  for I := 0 to Methods.Count - 1 do
    if SameText(Methods[I].Name, Name) then
      Exit(Methods[I]);
  Result := nil;
end;

{ TXmlDocMethod }

constructor TXmlDocMethod.Create;
begin
  inherited Create;
  FNotes := TXmlDocNotes.Create;
end;

destructor TXmlDocMethod.Destroy;
begin
  FNotes.Free;
  inherited;
end;

{ TXmlDocInfo }

constructor TXmlDocInfo.Create;
begin
  inherited Create;
  FUnits := TObjectList<TXmlDocUnit>.Create;
end;

destructor TXmlDocInfo.Destroy;
begin
  FUnits.Free;
  inherited;
end;

function TXmlDocInfo.UnitByName(const Name: string): TXmlDocUnit;
var
  I: Integer;
begin
  for I := 0 to Units.Count - 1 do
    if SameText(Units[I].Name, Name) then
      Exit(Units[I]);
  Result := nil;
end;

{ TXmlDocNotes }

constructor TXmlDocNotes.Create;
begin
  inherited Create;
  FParams := TObjectList<TXmlDocNotesItem>.Create;
  FSwaggerItems := TObjectList<TXmlDocNotesItem>.Create;
end;

destructor TXmlDocNotes.Destroy;
begin
  FParams.Free;
  FSwaggerItems.Free;
  inherited;
end;

function TXmlDocNotes.ParamContent(const ParamName: string): string;
var
  I: Integer;
begin
  for I := 0 to Params.Count - 1 do
    if SameText(ParamName, Params[I].Name) then
      Exit(Params[I].Content);
  Result := '';
end;

function TXmlDocNotes.SwaggerContent(const Name: string): string;
var
  I: Integer;
begin
  for I := 0 to SwaggerItems.Count - 1 do
    if SameText(Name, SwaggerItems[I].Name) then
      Exit(SwaggerItems[I].Content);
  Result := '';
end;

{ TXmlDocNotesItem }

constructor TXmlDocNotesItem.Create(const AName, AContent: string);
begin
  inherited Create;
  FName := AName;
  FContent := AContent;
end;

{ TXmlDocClass }

constructor TXmlDocClass.Create;
begin
  inherited Create;
  FMembers := TObjectList<TXmlDocMember>.Create;
  FNotes := TXmlDocNotes.Create;
end;

destructor TXmlDocClass.Destroy;
begin
  FMembers.Free;
  FNotes.Free;
  inherited;
end;

function TXmlDocClass.MemberByName(const Name: string): TXmlDocMember;
var
  I: Integer;
begin
  for I := 0 to Members.Count - 1 do
    if SameText(Members[I].Name, Name) then
      Exit(Members[I]);
  Result := nil;
end;

{ TXmlDocMember }

constructor TXmlDocMember.Create;
begin
  inherited Create;
  FNotes := TXmlDocNotes.Create
end;

destructor TXmlDocMember.Destroy;
begin
  FNotes.Free;
  inherited;
end;

end.
