import { AuthCredentials } from "./authEntity";

const create = (
  accessToken: AuthCredentials["accessToken"],
  refreshToken: AuthCredentials["refreshToken"]
): AuthCredentials => ({
  accessToken: accessToken,
  refreshToken: refreshToken,
});

const update = (
  credentials: AuthCredentials,
  payload: Partial<AuthCredentials>
) => ({
  ...credentials,
  ...payload,
});

const refreshTokens = (
  credentials: AuthCredentials,
  payload: Required<Pick<AuthCredentials, "accessToken" | "refreshToken">>
) =>
  update(credentials, {
    accessToken: payload.accessToken,
    refreshToken: payload.refreshToken,
  });

export { create, update, refreshTokens };
