unit Azure.CognitiveServices.Core.Entities;

interface

type

  IAcsConfiguration = interface
    ['{31C10E56-7B2B-4E5D-8EFB-8963B33D43AD}']
    function GetSubscriptionKey: string;
    procedure SetSubscriptionKey(const AValue: string);
    property SubscriptionKey: string read GetSubscriptionKey write SetSubscriptionKey;
  end;

function GetAcsConfiguration: IAcsConfiguration;
function LoadAcsConfiguration: IAcsConfiguration;

implementation

uses
  System.IniFiles, System.IOUtils;

type

  TAzureCsConfiguration = class(TInterfacedObject, IAcsConfiguration)
  private
    FSubscriptionKey: string;
  public
    function GetSubscriptionKey: string;
    procedure SetSubscriptionKey(const AValue: string);
  end;

function GetAcsConfiguration: IAcsConfiguration;
begin
  Result := TAzureCsConfiguration.Create;
end;

function LoadAcsConfiguration: IAcsConfiguration;
var
  LIni: TMemIniFile;
begin
  Result := TAzureCsConfiguration.Create;
  LIni := TMemIniFile.Create(TPath.Combine(
    TPath.GetDirectoryName(ParamStr(0)),
    'AzureCognitiveServices.ini'));
  try
    Result.SubscriptionKey := LIni.ReadString('General', 'SubscriptionKey', '');
  finally
    LIni.Free;
  end;
end;

function TAzureCsConfiguration.GetSubscriptionKey: string;
begin
  Result := FSubscriptionKey;
end;

procedure TAzureCsConfiguration.SetSubscriptionKey(const AValue: string);
begin
  FSubscriptionKey := AValue;
end;

end.
