import { eLevel } from '@/types/level'
import { eNewRoleRelatedToBackEnd, eRole } from '@/types/role'
import { iUserMsg } from '../userMsg/types'

export function getOldRoleFromUserMsg(usermsg: iUserMsg): eRole | undefined {
  if (usermsg.newRole === eNewRoleRelatedToBackEnd.PlatformAdmin)
    return eRole.platform_management
  else if (usermsg.newRole === eNewRoleRelatedToBackEnd.BackAdmin)
    return eRole.superManager
  else {
    if (usermsg.level === eLevel.firstLevel_branch) {
      return eRole.firstLevel_branch
    } else if (usermsg.level === eLevel.secondary_branch) {
      return eRole.secondary_branch
    } else if (usermsg.level === eLevel.firstLevel_sub_branch) {
      return usermsg.newRole === eNewRoleRelatedToBackEnd.ACM
        ? eRole.firstLevel_sub_clientManager
        : eRole.firstLevel_sub_branch
    } else if (usermsg.level === eLevel.secondary_sub_branch) {
      return usermsg.newRole === eNewRoleRelatedToBackEnd.ACM
        ? eRole.secondary_sub_clientManager
        : eRole.secondary_sub_branch
    }
  }
}
