<?php

namespace App\Services\Auth;

use App\Models\User;

class PortalRedirectService
{
    /** @var list<string> */
    private const ADMIN_ROLES = [
        'Super Admin',
        'Administrator',
        'Bursar',
        'Accountant',
        'Auditor',
        'Registrar',
        'Headmaster',
    ];

    public function homeRouteName(User $user): string
    {
        if ($user->hasRole('Parent') && ! $user->hasAnyRole(self::ADMIN_ROLES) && ! $user->hasRole('Teacher')) {
            return 'parent.dashboard';
        }

        if ($user->hasRole('Student') && ! $user->hasAnyRole(self::ADMIN_ROLES) && ! $user->hasRole('Teacher')) {
            return 'student.dashboard';
        }

        if ($user->hasRole('Teacher') && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'teacher.home';
        }

        if ($user->hasAnyRole(['Librarian', 'Front Desk']) && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'staff.dashboard';
        }

        return 'admin.dashboard';
    }

    public function portalLabel(User $user): string
    {
        if ($user->hasRole('Parent') && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'Parent Portal';
        }

        if ($user->hasRole('Student') && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'Student Portal';
        }

        if ($user->hasRole('Teacher') && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'Teacher Portal';
        }

        if ($user->hasAnyRole(['Librarian', 'Front Desk']) && ! $user->hasAnyRole(self::ADMIN_ROLES)) {
            return 'Staff Portal';
        }

        return 'Admin';
    }
}
