import * as plugins from '../loint-reception.plugins.js';
import * as data from '../data/index.js';

export interface IReq_LoginWithEmailOrUsernameAndPassword
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_LoginWithEmailOrUsernameAndPassword
  > {
  method: 'loginWithEmailOrUsernameAndPassword';
  request: {
    username: string;
    password: string;
  };
  response: {
    refreshToken?: string;
    twoFaNeeded: boolean;
  };
}

export interface IReq_LoginWithEmail
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_LoginWithEmailOrUsernameAndPassword
  > {
  method: 'loginWithEmail';
  request: {
    email: string;
  };
  response: {
    status: 'ok' | 'not ok';
    testOnlyToken?: string;
  };
}

export interface IReq_LoginWithEmailAfterEmailTokenAquired
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_LoginWithEmailOrUsernameAndPassword
  > {
  method: 'loginWithEmailAfterEmailTokenAquired';
  request: {
    email: string;
    token: string;
  };
  response: {
    refreshToken: string;
  };
}

/**
 * in case you authenticate with a long lived api token
 */
export interface IReq_LoginWithApiToken
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_LoginWithApiToken
  > {
  method: 'loginWithApiToken';
  request: {
    apiToken: string;
  };
  response: {
    jwt?: string;
  };
}

export interface ILogoutRequest
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    ILogoutRequest
  > {
  method: 'logout';
  request: {
    refreshToken: string;
  };
  response: {};
}

export interface IReq_RefreshJwt
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_RefreshJwt
  > {
  method: 'refreshJwt';
  request: {
    refreshToken: string;
  };
  response: {
    status: data.TLoginStatus;
    jwt: string;
  };
}

/**
 * allows the exchange between refreshToken and transferTokens
 */
export interface IReq_ExchangeRefreshTokenAndTransferToken
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_ExchangeRefreshTokenAndTransferToken
  > {
  method: 'exchangeRefreshTokenAndTransferToken';
  request: {
    transferToken?: string;
    refreshToken?: string;
    appData: data.IApp;
  };
  response: {
    refreshToken?: string;
    transferToken?: string;
  };
}

/**
 * in case you authenticate with a long lived api token
 */
export interface IReq_ResetPassword
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_ResetPassword
  > {
  method: 'resetPassword';
  request: {
    email: string;
  };
  response: {
    status: 'ok' | 'not ok';
  };
}

/**
 * in cse you authenticate with a long lived api token
 */
export interface IReq_SetNewPassword
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_SetNewPassword
  > {
  method: 'setNewPassword';
  request: {
    email: string;
    oldPassword?: string;
    tokenArg?: string;
    newPassword: string;
  };
  response: {
    status: 'ok' | 'not ok';
  };
}

export interface IReq_ObtainDeviceId
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_ObtainDeviceId
  > {
  method: 'obtainDeviceId';
  request: {};
  response: {
    deviceId: data.IDevice;
  };
}

/**
 * allows attaching a device id to a login session
 * to share a login session across contexts
 */
export interface IReq_AttachDeviceId
  extends plugins.typedRequestInterfaces.implementsTR<
    plugins.typedRequestInterfaces.ITypedRequest,
    IReq_AttachDeviceId
  > {
  method: 'attachDeviceId';
  request: {
    jwt: string;
    deviceId: string;
  };
  response: {
    ok: boolean;
  };
}
