import { ref } from 'vue';
import { getAllRoleList } from '@/api/user';
import { AUTHENTICATION_ROLE } from '@/config/constants';

export default function useAuthenRole() {
  const roleList = ref([]);

  const getRoleList = async () => {
    if (roleList.value.length) return;
    const res = await getAllRoleList().catch(() => {});
    if (!res) return;
    const validTypes = Object.keys(AUTHENTICATION_ROLE);
    roleList.value = res.filter((item) => validTypes.includes(item.type));
  };

  return {
    roleList,
    getRoleList,
  };
}
