using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Domain.Identity;

namespace Jiaowu.Api.Infrastructure.Auth;

public static class CourseMaintenancePolicy
{
    public static bool CanManage(
        CurrentUserScope scope,
        Guid collegeId,
        CourseNature nature)
    {
        if (scope.IsInRole(SystemRoles.SuperAdmin) ||
            scope.IsInRole(SystemRoles.AcademicAdmin))
            return true;

        return scope.IsInRole(SystemRoles.CollegeAdmin) &&
               scope.CollegeId == collegeId &&
               IsCollegeMaintainedNature(nature);
    }

    public static bool IsCollegeMaintainedNature(CourseNature nature) =>
        nature is CourseNature.MajorRequired or
            CourseNature.MajorElective or
            CourseNature.Practice;
}
