"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var auth_exports = {};
__export(auth_exports, {
  authentication: () => authentication,
  login: () => login,
  logout: () => logout
});
module.exports = __toCommonJS(auth_exports);
var import_effects = require("redux-saga/effects");
var import_actions = require("../../data/auth/actions.js");
var import_auth = require("../../utils/auth/index.js");
var import_logger = require("../../utils/logger.js");
var import_log_records = require("../../utils/log-records.js");
function* login({
  payload
}) {
  try {
    yield (0, import_effects.call)(import_auth.authorize, payload);
    yield (0, import_effects.put)({ type: import_actions.LOGIN_SUCCESS });
  } catch (err) {
    (0, import_logger.getLogger)()?.error({
      ...import_log_records.logRecords.LOGIN_FAILED,
      exception: err
    });
  }
}
function* logout({
  payload
}) {
  try {
    yield (0, import_effects.call)(import_auth.endSession, payload);
  } catch (err) {
    (0, import_logger.getLogger)()?.error({
      ...import_log_records.logRecords.LOGOUT_FAILED,
      exception: err
    });
  }
}
function* authentication() {
  yield (0, import_effects.takeLatest)(import_actions.LOGIN, login);
  yield (0, import_effects.takeLatest)(import_actions.LOGOUT, logout);
}
