{"size": 2149, "ext": "js", "max_stars_repo_path": "src/store/modules/reports.js", "max_stars_repo_name": "lwhitelock/cipp-admin", "max_stars_repo_stars_event_min_datetime": "2021-11-04T21:25:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-11T19:04:24.000Z", "max_issues_repo_path": "src/store/modules/reports.js", "max_issues_repo_name": "lwhitelock/cipp-admin", "max_issues_repo_issues_event_min_datetime": "2021-12-05T03:28:20.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-05T03:28:20.000Z", "max_forks_repo_path": "src/store/modules/reports.js", "max_forks_repo_name": "lwhitelock/cipp-admin", "max_forks_repo_forks_event_min_datetime": "2021-11-03T23:50:42.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-30T19:51:38.000Z"}
{"max_stars_count": 5, "max_issues_count": 1, "max_forks_count": 5, "avg_line_length": 22.3854166667, "max_line_length": 76, "alphanum_fraction": 0.5635179153}
const initialState = {
  mfa: {
    report: [],
    loading: false,
    loaded: false,
  },
  basicAuth: {
    report: [],
    loading: false,
    loaded: false,
  },
}

const MFA_LOAD = 'reports/MFA_LOAD'
const MFA_LOAD_SUCCESS = 'reports/MFA_LOAD_SUCCESS'
const MFA_LOAD_FAIL = 'reports/MFA_LOAD_FAIL'

const BASIC_AUTH_LOAD = 'reports/BASIC_AUTH_LOAD'
const BASIC_AUTH_LOAD_SUCCESS = 'reports/BASIC_AUTH_LOAD_SUCCESS'
const BASIC_AUTH_LOAD_FAIL = 'reports/BASIC_AUTH_LOAD_FAIL'

export default function reducer(state = initialState, action = {}) {
  switch (action.type) {
    case MFA_LOAD:
      return {
        ...state,
        mfa: {
          ...state.mfa,
          loading: true,
          loaded: false,
        },
      }
    case MFA_LOAD_SUCCESS:
      return {
        ...state,
        mfa: {
          ...state.mfa,
          report: action.result,
          loading: false,
          loaded: true,
        },
      }
    case MFA_LOAD_FAIL:
      return {
        ...state,
        mfa: initialState.mfa,
      }
    case BASIC_AUTH_LOAD:
      return {
        ...state,
        basicAuth: {
          ...state.basicAuth,
          loading: true,
          loaded: false,
        },
      }
    case BASIC_AUTH_LOAD_SUCCESS:
      return {
        ...state,
        basicAuth: {
          ...state.basicAuth,
          report: action.result,
          loading: false,
          loaded: true,
        },
      }
    case BASIC_AUTH_LOAD_FAIL:
      return {
        ...state,
        basicAuth: initialState.basicAuth,
      }
    default:
      return state
  }
}

export function loadMFAReport({ domain }) {
  return {
    types: [MFA_LOAD, MFA_LOAD_SUCCESS, MFA_LOAD_FAIL],
    promise: (client) =>
      client
        .get('/api/ListMFAUsers', { params: { TenantFilter: domain } })
        .then((result) => result.data),
  }
}

export function loadBasicAuthReport({ domain }) {
  return {
    types: [BASIC_AUTH_LOAD, BASIC_AUTH_LOAD_SUCCESS, BASIC_AUTH_LOAD_FAIL],
    promise: (client) =>
      client
        .get('/api/ListBasicAuth', { params: { TenantFilter: domain } })
        .then((result) => result.data),
  }
}
