unit Auth.Service;

interface

uses
  XData.Service.Common,
  Aurelius.Mapping.Attributes,
  System.Generics.Collections,
  System.JSON;

const
  AUTH_MODEL = 'Auth';

type
  TAgencyItem = class
  public
    agency: String;
    constructor Create( AAgency : String );
  end;

  TAgenciesList = class
  public
    count: integer;
    returned: integer;
    data: TList<TAgencyItem>;
  end;

  TAgencyConfigItem = class
  public
    id: string;
    agency: String;
    name: String;
  end;

  TAgencyConfigList = class
  public
    count: integer;
    returned: integer;
    data: TList<TAgencyConfigItem>;
  end;

  // Device record returned by GetDeviceList (Api.Service)
  TDeviceItem = class
  public
    id: Integer;
    credential_id: string;
    device_name: string;
    user_agent: string;
    registered_at: string;
    revoked_at: string;
    revoked_by: string;
  end;

  TDeviceList = class
  public
    count: Integer;
    returned: Integer;
    data: TList<TDeviceItem>;
  end;

  [ServiceContract, Model(AUTH_MODEL)]
  IAuthService = interface(IInvokable)
  ['{D2290B28-964C-4155-A83A-DAE87C4C7FE7}']
    // Full WebAuthn assertion login — issues JWT on success
    function Login(const user, password, agency, credentialId,
                   challengeToken, authenticatorData, clientDataJSON,
                   signature: string): string;

    [HttpGet] function GetAgenciesList(): TAgenciesList;
    [HttpGet] function GetAgencyConfigList: TAgencyConfigList;
    function VerifyVersion(ClientVersion: string): TJSONObject;

    // WebAuthn registration — step 1: server returns challenge + rpId/rpName
    function BeginRegistration(const DeviceName: string): TJSONObject;
    // WebAuthn registration — step 2: client submits credential, server verifies + stores
    function CompleteRegistration(const DeviceName, CredentialId,
                                  AttestationObject, ClientDataJSON,
                                  ChallengeToken: string): TJSONObject;
    // WebAuthn authentication challenge — called before Login
    function BeginAuthentication(const CredentialId: string): TJSONObject;
  end;

implementation

{ TAgencyItem }

constructor TAgencyItem.Create(AAgency: String);
begin
  agency := AAgency;
end;

end.
