unit Test.DistributionConfig;

interface

uses
  System.SysUtils;

const
  cServicePort = 2030;

  cXDataUrlPath = 'SphinxLogoutTestServer';
  cSphinxUrlPath = 'SphinxLogoutTestAuth';

  cBrowserHost = '127.0.0.1';
  cWebStaticPort = 8000;
  cWebAppVirtualDir = 'SphinxLogoutTestWeb';

  cFirebirdUser = 'sysdba';
  cFirebirdPassword = 'masterkey';
  cConnectionPoolSize = 10;

  cDataSubfolder = 'Data';
  cLogsSubfolder = 'Logs';
  cLoginAppSubfolder = 'loginapp';
  cDatabaseFileName = 'sphinxlogout.fdb';

{$IFNDEF PAS2JS}
function Dist_ExeDirectory: string;
function Dist_DatabaseFile: string;
function Dist_LogPath: string;
function Dist_LoginAppFolder: string;
procedure Dist_EnsureRuntimeDirectories;
{$ENDIF}

function Dist_DefaultXDataBaseUrl: string;
function Dist_DefaultSphinxAuthUrl: string;

function Dist_BrowserXDataUrl: string;
function Dist_BrowserAuthUrl: string;

function Dist_OAuthRedirectBase: string;
function Dist_OAuthRedirectIndexHtml: string;

implementation

{$IFNDEF PAS2JS}
uses
  System.IOUtils;
{$ENDIF}

function Dist_DefaultXDataBaseUrl: string;
begin
  Result := Format('http://+:%d/%s', [cServicePort, cXDataUrlPath]);
end;

function Dist_DefaultSphinxAuthUrl: string;
begin
  Result := Format('http://+:%d/%s', [cServicePort, cSphinxUrlPath]);
end;

function Dist_BrowserXDataUrl: string;
begin
  Result := Format('http://%s:%d/%s', [cBrowserHost, cServicePort, cXDataUrlPath]);
end;

function Dist_BrowserAuthUrl: string;
begin
  Result := Format('http://%s:%d/%s', [cBrowserHost, cServicePort, cSphinxUrlPath]);
end;

function Dist_OAuthRedirectBase: string;
begin
  Result := Format('http://%s:%d/%s/', [cBrowserHost, cWebStaticPort, cWebAppVirtualDir]);
end;

function Dist_OAuthRedirectIndexHtml: string;
begin
  Result := Dist_OAuthRedirectBase + 'Index.html';
end;

{$IFNDEF PAS2JS}

function Dist_ExeDirectory: string;
begin
  Result := TPath.GetDirectoryName(ParamStr(0));
end;

function Dist_DatabaseFile: string;
begin
  Result := TPath.Combine(TPath.Combine(Dist_ExeDirectory, cDataSubfolder), cDatabaseFileName);
end;

function Dist_LogPath: string;
begin
  Result := TPath.Combine(Dist_ExeDirectory, cLogsSubfolder);
end;

function Dist_LoginAppFolder: string;
begin
  Result := TPath.Combine(Dist_ExeDirectory, cLoginAppSubfolder);
end;

procedure Dist_EnsureRuntimeDirectories;
begin
  TDirectory.CreateDirectory(TPath.Combine(Dist_ExeDirectory, cDataSubfolder));
  TDirectory.CreateDirectory(Dist_LogPath);
end;

{$ENDIF}

end.
