import SecurityService, { ROLE_IS_LOGGED_IN, ACTION_DENY, ACTION_ALLOW } from '@/plugins/security'
// import store from '../store'
import {
  IS_LOGGED_IN_GETTER_NAME,
  HOME_PAGE_URL,
  LOG_IN_MUTATION_TYPE,
  LOG_OUT_MUTATION_TYPE,
  LOGIN_URL,
} from './defaults'
import { ENROLMENT_START, VIREL, GENEALOGY_PLACEMENT_TREE, ON_BEHALF } from './url-prefix'

SecurityService.accessDeniedPage = '/'

SecurityService.routes.rules([
  { path: '^/*', role: ROLE_IS_LOGGED_IN, action: ACTION_ALLOW, to: { path: LOGIN_URL } },
  {
    path: '^/user/login/contact',
    role: ROLE_IS_LOGGED_IN,
    action: ACTION_ALLOW,
    to: { path: LOGIN_URL },
    propagation: false,
  },
  {
    path: '^/user/login/change-password',
    role: ROLE_IS_LOGGED_IN,
    action: ACTION_ALLOW,
    to: { path: LOGIN_URL },
    propagation: false,
  },
  { path: '^/user/login', role: ROLE_IS_LOGGED_IN, action: ACTION_DENY, to: { path: HOME_PAGE_URL } },
  { path: '^/user/reset-password', role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^/enrol', role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^/enrollment-files', role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^/enrolment/process/start', role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^' + ENROLMENT_START, role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^' + GENEALOGY_PLACEMENT_TREE, role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^' + VIREL, role: ROLE_IS_LOGGED_IN, toSkip: true },
  { path: '^' + ON_BEHALF, role: ROLE_IS_LOGGED_IN, toSkip: true },
])

export default SecurityService
