unit Chilkat.Secrets;

{
  Pascal wrapper for Chilkat Secrets.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TSecrets wraps CkSecrets via the C bridge layer. }
  TSecrets = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetUncommonOptions: string;
    procedure SetUncommonOptions(AValue: string);
    function  GetLocation: string;
    procedure SetLocation(AValue: string);
    function  GetCompression: Boolean;
    procedure SetCompression(AValue: Boolean);
    function  GetAutoSplit: Boolean;
    procedure SetAutoSplit(AValue: Boolean);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;
    property Location: string read GetLocation write SetLocation;
    property Compression: Boolean read GetCompression write SetCompression;
    property AutoSplit: Boolean read GetAutoSplit write SetAutoSplit;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  GetSecretStr(jsonId: TChilkatBase): string;
    function  GetSecretBd(jsonId: TChilkatBase; bd: TChilkatBase): Boolean;
    function  GetSecretJson(jsonId: TChilkatBase; jsonOut: TChilkatBase): Boolean;
    function  UpdateSecretStr(jsonId: TChilkatBase; const secret: string): Boolean;
    function  UpdateSecretJson(jsonId: TChilkatBase; secret: TChilkatBase): Boolean;
    function  UpdateSecretBd(jsonId: TChilkatBase; secret: TChilkatBase): Boolean;
    function  DeleteSecret(jsonId: TChilkatBase): Boolean;
    function  ListSecrets(json: TChilkatBase; jsonOut: TChilkatBase): Boolean;
    function  SetBootstrapSecret(jsonId: TChilkatBase; secretContent: TChilkatBase): Boolean;
    function  GetSecretSb(jsonId: TChilkatBase; sb: TChilkatBase): Boolean;
    function  UpdateSecretSb(jsonId: TChilkatBase; sb: TChilkatBase): Boolean;
    function  SecretSpecToJson(const secretSpec: string; json: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkSecrets_Create  = function(): Pointer; cdecl;
  TCkSecrets_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkSecrets_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkSecrets_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkSecrets_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkSecrets_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSecrets_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkSecrets_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSecrets_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkSecrets_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSecrets_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSecrets_get_Location = function(handle: Pointer): PAnsiChar; cdecl;
  TCkSecrets_put_Location = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkSecrets_get_Compression = function(handle: Pointer): LongBool; cdecl;
  TCkSecrets_put_Compression = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSecrets_get_AutoSplit = function(handle: Pointer): LongBool; cdecl;
  TCkSecrets_put_AutoSplit = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkSecrets_GetSecretStr = function(handle: Pointer; jsonId: Pointer): PAnsiChar; cdecl;
  TCkSecrets_GetSecretBd = function(handle: Pointer; jsonId: Pointer; bd: Pointer): LongBool; cdecl;
  TCkSecrets_GetSecretJson = function(handle: Pointer; jsonId: Pointer; jsonOut: Pointer): LongBool; cdecl;
  TCkSecrets_UpdateSecretStr = function(handle: Pointer; jsonId: Pointer; secret: PAnsiChar): LongBool; cdecl;
  TCkSecrets_UpdateSecretJson = function(handle: Pointer; jsonId: Pointer; secret: Pointer): LongBool; cdecl;
  TCkSecrets_UpdateSecretBd = function(handle: Pointer; jsonId: Pointer; secret: Pointer): LongBool; cdecl;
  TCkSecrets_DeleteSecret = function(handle: Pointer; jsonId: Pointer): LongBool; cdecl;
  TCkSecrets_ListSecrets = function(handle: Pointer; json: Pointer; jsonOut: Pointer): LongBool; cdecl;
  TCkSecrets_SetBootstrapSecret = function(handle: Pointer; jsonId: Pointer; secretContent: Pointer): LongBool; cdecl;
  TCkSecrets_GetSecretSb = function(handle: Pointer; jsonId: Pointer; sb: Pointer): LongBool; cdecl;
  TCkSecrets_UpdateSecretSb = function(handle: Pointer; jsonId: Pointer; sb: Pointer): LongBool; cdecl;
  TCkSecrets_SecretSpecToJson = function(handle: Pointer; secretSpec: PAnsiChar; json: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkSecrets_Create:  TCkSecrets_Create  = nil;
  CkSecrets_Dispose: TCkSecrets_Dispose = nil;
  CkSecrets_SetAbortCheckCallback:   TCkSecrets_SetAbortCheckCallback   = nil;
  CkSecrets_SetPercentDoneCallback:  TCkSecrets_SetPercentDoneCallback  = nil;
  CkSecrets_SetProgressInfoCallback: TCkSecrets_SetProgressInfoCallback = nil;
  CkSecrets_get_LastErrorHtml: TCkSecrets_get_LastErrorHtml = nil;
  CkSecrets_get_LastErrorText: TCkSecrets_get_LastErrorText = nil;
  CkSecrets_get_LastErrorXml: TCkSecrets_get_LastErrorXml = nil;
  CkSecrets_get_Version: TCkSecrets_get_Version = nil;
  CkSecrets_get_DebugLogFilePath: TCkSecrets_get_DebugLogFilePath = nil;
  CkSecrets_put_DebugLogFilePath: TCkSecrets_put_DebugLogFilePath = nil;
  CkSecrets_get_VerboseLogging: TCkSecrets_get_VerboseLogging = nil;
  CkSecrets_put_VerboseLogging: TCkSecrets_put_VerboseLogging = nil;
  CkSecrets_get_LastMethodSuccess: TCkSecrets_get_LastMethodSuccess = nil;
  CkSecrets_put_LastMethodSuccess: TCkSecrets_put_LastMethodSuccess = nil;
  CkSecrets_get_UncommonOptions: TCkSecrets_get_UncommonOptions = nil;
  CkSecrets_put_UncommonOptions: TCkSecrets_put_UncommonOptions = nil;
  CkSecrets_get_Location: TCkSecrets_get_Location = nil;
  CkSecrets_put_Location: TCkSecrets_put_Location = nil;
  CkSecrets_get_Compression: TCkSecrets_get_Compression = nil;
  CkSecrets_put_Compression: TCkSecrets_put_Compression = nil;
  CkSecrets_get_AutoSplit: TCkSecrets_get_AutoSplit = nil;
  CkSecrets_put_AutoSplit: TCkSecrets_put_AutoSplit = nil;
  CkSecrets_GetSecretStr: TCkSecrets_GetSecretStr = nil;
  CkSecrets_GetSecretBd: TCkSecrets_GetSecretBd = nil;
  CkSecrets_GetSecretJson: TCkSecrets_GetSecretJson = nil;
  CkSecrets_UpdateSecretStr: TCkSecrets_UpdateSecretStr = nil;
  CkSecrets_UpdateSecretJson: TCkSecrets_UpdateSecretJson = nil;
  CkSecrets_UpdateSecretBd: TCkSecrets_UpdateSecretBd = nil;
  CkSecrets_DeleteSecret: TCkSecrets_DeleteSecret = nil;
  CkSecrets_ListSecrets: TCkSecrets_ListSecrets = nil;
  CkSecrets_SetBootstrapSecret: TCkSecrets_SetBootstrapSecret = nil;
  CkSecrets_GetSecretSb: TCkSecrets_GetSecretSb = nil;
  CkSecrets_UpdateSecretSb: TCkSecrets_UpdateSecretSb = nil;
  CkSecrets_SecretSpecToJson: TCkSecrets_SecretSpecToJson = nil;

constructor TSecrets.Create;
begin
  inherited Create;
  FHandle := CkSecrets_Create();
end;

destructor TSecrets.Destroy;
begin
  if FHandle <> nil then
    CkSecrets_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TSecrets_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TSecrets;
begin
  Result := 0;
  obj := TSecrets(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TSecrets_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TSecrets;
begin
  Result := 0;
  obj := TSecrets(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TSecrets_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TSecrets;
begin
  obj := TSecrets(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TSecrets.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkSecrets_SetAbortCheckCallback(FHandle, @TSecrets_AbortCheckThunk, Self)
  else
    CkSecrets_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TSecrets.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkSecrets_SetPercentDoneCallback(FHandle, @TSecrets_PercentDoneThunk, Self)
  else
    CkSecrets_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TSecrets.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkSecrets_SetProgressInfoCallback(FHandle, @TSecrets_ProgressInfoThunk, Self)
  else
    CkSecrets_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TSecrets.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkSecrets_get_LastErrorHtml(FHandle));
end;

function TSecrets.GetLastErrorText: string;
begin
  Result := CkToStr(CkSecrets_get_LastErrorText(FHandle));
end;

function TSecrets.GetLastErrorXml: string;
begin
  Result := CkToStr(CkSecrets_get_LastErrorXml(FHandle));
end;

function TSecrets.GetVersion: string;
begin
  Result := CkToStr(CkSecrets_get_Version(FHandle));
end;

function TSecrets.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkSecrets_get_DebugLogFilePath(FHandle));
end;

procedure TSecrets.SetDebugLogFilePath(AValue: string);
begin
  CkSecrets_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSecrets.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkSecrets_get_VerboseLogging(FHandle));
end;

procedure TSecrets.SetVerboseLogging(AValue: Boolean);
begin
  CkSecrets_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TSecrets.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkSecrets_get_LastMethodSuccess(FHandle));
end;

procedure TSecrets.SetLastMethodSuccess(AValue: Boolean);
begin
  CkSecrets_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TSecrets.GetUncommonOptions: string;
begin
  Result := CkToStr(CkSecrets_get_UncommonOptions(FHandle));
end;

procedure TSecrets.SetUncommonOptions(AValue: string);
begin
  CkSecrets_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSecrets.GetLocation: string;
begin
  Result := CkToStr(CkSecrets_get_Location(FHandle));
end;

procedure TSecrets.SetLocation(AValue: string);
begin
  CkSecrets_put_Location(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TSecrets.GetCompression: Boolean;
begin
  Result := Boolean(CkSecrets_get_Compression(FHandle));
end;

procedure TSecrets.SetCompression(AValue: Boolean);
begin
  CkSecrets_put_Compression(FHandle, LongBool(AValue));
end;

function TSecrets.GetAutoSplit: Boolean;
begin
  Result := Boolean(CkSecrets_get_AutoSplit(FHandle));
end;

procedure TSecrets.SetAutoSplit(AValue: Boolean);
begin
  CkSecrets_put_AutoSplit(FHandle, LongBool(AValue));
end;

function TSecrets.GetSecretStr(jsonId: TChilkatBase): string;
begin
  Result := CkToStr(CkSecrets_GetSecretStr(FHandle, jsonId.Handle));
end;

function TSecrets.GetSecretBd(jsonId: TChilkatBase; bd: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_GetSecretBd(FHandle, jsonId.Handle, bd.Handle));
end;

function TSecrets.GetSecretJson(jsonId: TChilkatBase; jsonOut: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_GetSecretJson(FHandle, jsonId.Handle, jsonOut.Handle));
end;

function TSecrets.UpdateSecretStr(jsonId: TChilkatBase; const secret: string): Boolean;
begin
  Result := Boolean(CkSecrets_UpdateSecretStr(FHandle, jsonId.Handle, PAnsiChar(StrToCk(secret))));
end;

function TSecrets.UpdateSecretJson(jsonId: TChilkatBase; secret: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_UpdateSecretJson(FHandle, jsonId.Handle, secret.Handle));
end;

function TSecrets.UpdateSecretBd(jsonId: TChilkatBase; secret: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_UpdateSecretBd(FHandle, jsonId.Handle, secret.Handle));
end;

function TSecrets.DeleteSecret(jsonId: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_DeleteSecret(FHandle, jsonId.Handle));
end;

function TSecrets.ListSecrets(json: TChilkatBase; jsonOut: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_ListSecrets(FHandle, json.Handle, jsonOut.Handle));
end;

function TSecrets.SetBootstrapSecret(jsonId: TChilkatBase; secretContent: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_SetBootstrapSecret(FHandle, jsonId.Handle, secretContent.Handle));
end;

function TSecrets.GetSecretSb(jsonId: TChilkatBase; sb: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_GetSecretSb(FHandle, jsonId.Handle, sb.Handle));
end;

function TSecrets.UpdateSecretSb(jsonId: TChilkatBase; sb: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_UpdateSecretSb(FHandle, jsonId.Handle, sb.Handle));
end;

function TSecrets.SecretSpecToJson(const secretSpec: string; json: TChilkatBase): Boolean;
begin
  Result := Boolean(CkSecrets_SecretSpecToJson(FHandle, PAnsiChar(StrToCk(secretSpec)), json.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkSecrets_Create,  'CkSecrets_Create');
  Chilkat_GetProcedureAddress(CkSecrets_Dispose, 'CkSecrets_Dispose');
  Chilkat_GetProcedureAddress(CkSecrets_SetAbortCheckCallback, 'CkSecrets_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkSecrets_SetPercentDoneCallback, 'CkSecrets_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkSecrets_SetProgressInfoCallback, 'CkSecrets_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkSecrets_get_LastErrorHtml, 'CkSecrets_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkSecrets_get_LastErrorText, 'CkSecrets_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkSecrets_get_LastErrorXml, 'CkSecrets_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkSecrets_get_Version, 'CkSecrets_get_Version');
  Chilkat_GetProcedureAddress(CkSecrets_get_DebugLogFilePath, 'CkSecrets_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkSecrets_put_DebugLogFilePath, 'CkSecrets_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkSecrets_get_VerboseLogging, 'CkSecrets_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkSecrets_put_VerboseLogging, 'CkSecrets_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkSecrets_get_LastMethodSuccess, 'CkSecrets_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkSecrets_put_LastMethodSuccess, 'CkSecrets_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkSecrets_get_UncommonOptions, 'CkSecrets_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkSecrets_put_UncommonOptions, 'CkSecrets_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkSecrets_get_Location, 'CkSecrets_get_Location');
  Chilkat_GetProcedureAddress(CkSecrets_put_Location, 'CkSecrets_put_Location');
  Chilkat_GetProcedureAddress(CkSecrets_get_Compression, 'CkSecrets_get_Compression');
  Chilkat_GetProcedureAddress(CkSecrets_put_Compression, 'CkSecrets_put_Compression');
  Chilkat_GetProcedureAddress(CkSecrets_get_AutoSplit, 'CkSecrets_get_AutoSplit');
  Chilkat_GetProcedureAddress(CkSecrets_put_AutoSplit, 'CkSecrets_put_AutoSplit');
  Chilkat_GetProcedureAddress(CkSecrets_GetSecretStr, 'CkSecrets_GetSecretStr');
  Chilkat_GetProcedureAddress(CkSecrets_GetSecretBd, 'CkSecrets_GetSecretBd');
  Chilkat_GetProcedureAddress(CkSecrets_GetSecretJson, 'CkSecrets_GetSecretJson');
  Chilkat_GetProcedureAddress(CkSecrets_UpdateSecretStr, 'CkSecrets_UpdateSecretStr');
  Chilkat_GetProcedureAddress(CkSecrets_UpdateSecretJson, 'CkSecrets_UpdateSecretJson');
  Chilkat_GetProcedureAddress(CkSecrets_UpdateSecretBd, 'CkSecrets_UpdateSecretBd');
  Chilkat_GetProcedureAddress(CkSecrets_DeleteSecret, 'CkSecrets_DeleteSecret');
  Chilkat_GetProcedureAddress(CkSecrets_ListSecrets, 'CkSecrets_ListSecrets');
  Chilkat_GetProcedureAddress(CkSecrets_SetBootstrapSecret, 'CkSecrets_SetBootstrapSecret');
  Chilkat_GetProcedureAddress(CkSecrets_GetSecretSb, 'CkSecrets_GetSecretSb');
  Chilkat_GetProcedureAddress(CkSecrets_UpdateSecretSb, 'CkSecrets_UpdateSecretSb');
  Chilkat_GetProcedureAddress(CkSecrets_SecretSpecToJson, 'CkSecrets_SecretSpecToJson');

end.
