using Jiaowu.Api.Domain.Common;

namespace Jiaowu.Api.Domain.Academic;

public sealed class GradeSheet : EntityBase
{
    public Guid TeachingTaskId { get; set; }
    public TeachingTask? TeachingTask { get; set; }
    public decimal RegularWeight { get; set; } = 30;
    public decimal FinalWeight { get; set; } = 70;
    public GradeSheetStatus Status { get; set; } = GradeSheetStatus.Draft;
    public string? ReviewComment { get; set; }
    public DateTime? SubmittedAt { get; set; }
    public DateTime? ReviewedAt { get; set; }
    public DateTime? PublishedAt { get; set; }
    public ICollection<GradeRecord> Records { get; set; } = [];
    public ICollection<GradeItem> Items { get; set; } = [];
}

public sealed class GradeItem : EntityBase
{
    public Guid GradeSheetId { get; set; }
    public GradeSheet? GradeSheet { get; set; }
    public required string Name { get; set; }
    public decimal Weight { get; set; }
    public int SortOrder { get; set; }
    public GradeItemSourceType SourceType { get; set; } =
        GradeItemSourceType.Manual;
    public DateTime? SourceSnapshotAt { get; set; }
    public ICollection<GradeItemScore> Scores { get; set; } = [];
}

public sealed class GradeRecord : EntityBase
{
    public Guid GradeSheetId { get; set; }
    public GradeSheet? GradeSheet { get; set; }
    public Guid StudentId { get; set; }
    public Student? Student { get; set; }
    public decimal? RegularScore { get; set; }
    public decimal? FinalScore { get; set; }
    public decimal? TotalScore { get; set; }
    public decimal? GradePoint { get; set; }
    public GradeExamStatus ExamStatus { get; set; } = GradeExamStatus.Normal;
    public string? Notes { get; set; }
    public ICollection<GradeItemScore> ItemScores { get; set; } = [];
}

public sealed class GradeItemScore
{
    public Guid GradeRecordId { get; set; }
    public GradeRecord? GradeRecord { get; set; }
    public Guid GradeItemId { get; set; }
    public GradeItem? GradeItem { get; set; }
    public decimal? Score { get; set; }
}

public enum GradeSheetStatus
{
    Draft = 1,
    Submitted = 2,
    Approved = 3,
    Published = 4,
    Returned = 5
}

public enum GradeExamStatus
{
    Normal = 1,
    Absent = 2,
    Deferred = 3,
    Exempt = 4,
    Makeup = 5
}

public enum GradeItemSourceType
{
    Manual = 1,
    ExperimentSummary = 2
}
