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

namespace Jiaowu.Api.Infrastructure.Auth;

public static class TeachingTaskMaintenancePolicy
{
    public static bool CanManage(
        CurrentUserScope scope,
        Guid courseCollegeId,
        CourseNature nature)
    {
        if (scope.IsInRole(SystemRoles.SuperAdmin)) return true;
        if (scope.IsInRole(SystemRoles.AcademicAdmin) &&
            IsSchoolManagedNature(nature))
            return true;
        return scope.IsInRole(SystemRoles.CollegeAdmin) &&
               scope.CollegeId == courseCollegeId &&
               IsCollegeManagedNature(nature);
    }

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

    public static bool IsSchoolManagedNature(CourseNature nature) =>
        nature is CourseNature.GeneralRequired or
            CourseNature.GeneralElective;
}
