using TMSDAL.DTO.AttemptResponse;
namespace TMSDAL.DTO.AssessmentAttempt
{
///
/// Maps to DBO.TASSESSMENTATTEMPT
/// One assessment attempt per employee per enrollment.
/// Same employee can attempt multiple times up to MSESSIONASSESSMENT.MAXATTEMPTS.
/// Lifecycle: Started → Submitted → Evaluated (manual) → Pass/Fail.
/// AttemptIsPassed = 0 (Pending) until submitted or manually evaluated.
///
public class AssessmentAttemptDTO
{
// =====================================================
// PRIMARY KEY
// =====================================================
public int AssessmentAttemptId { get; set; }
// =====================================================
// FOREIGN KEYS + JOINED DISPLAY FIELDS
// =====================================================
/// FK → MSESSIONASSESSMENT.ASSESSMENTID
public int AssessmentId { get; set; }
/// Joined from MSESSIONASSESSMENT.ASSESSMENTTITLE
public string? AssessmentTitle { get; set; }
/// FK → TTRAININGENROLLMENT.ENROLLMENTID
public int EnrollmentId { get; set; }
/// Joined from TTRAININGENROLLMENT → MEMPLOYEE.EMPLOYEENAME
public string? EmployeeName { get; set; }
///
/// FK → MEMPLOYEE.EMPLOYEEID
/// -1 = Auto-evaluated. Positive = manual evaluator.
///
public int EvaluatedById { get; set; } = -1;
/// Joined from MEMPLOYEE.EMPLOYEENAME — null when auto-evaluated.
public string? EvaluatedByName { get; set; }
// =====================================================
// BUSINESS COLUMNS
// =====================================================
/// Attempt sequence. BLL computes as existingCount + 1.
public short AttemptNo { get; set; } = 1;
/// Set by BLL to DateTime.UtcNow on start.
public DateTime StartedOn { get; set; }
/// Null while in progress. Set by BLL on submit.
public DateTime? CompletedOn { get; set; }
/// Total possible marks. Copied from MSESSIONASSESSMENT.TOTALMARKS.
public int TotalMarks { get; set; } = 0;
/// Numeric(9,4) — sum of TATTEMPTRESPONSE.MARKSAWARDED.
public decimal MarksObtained { get; set; } = 0;
/// Numeric(9,4) — (MarksObtained / TotalMarks) * 100.
public decimal ScorePct { get; set; } = 0;
///
/// 0 = No / Pending manual evaluation.
/// 1 = Yes — ScorePct >= MSESSIONASSESSMENT.PASSTHRESHOLDPCT.
///
public byte AttemptIsPassed { get; set; } = 0;
/// 0 = No, 1 = Yes — synced to LMS by background job.
public byte IsLmsSynced { get; set; } = 0;
/// Optional evaluator or system remarks. Max 1000 chars.
public string? Remarks { get; set; }
/// 0 = InApp, 1 = Fls (link-delivered), 2 = Manual (offline/proctored entry).
public byte DeliveryChannel { get; set; } = 0;
// =====================================================
// CHILD COLLECTION
// Uses TMSDAL.DTO.AttemptResponse.AttemptResponseDTO — NOT a local class
// Populated on GetAttempt and GetAttemptList.
// Pass on Save/Submit with all responses included.
// =====================================================
public List? Responses { get; set; }
// =====================================================
// STANDARD FIELDS
// =====================================================
public short Version { get; set; }
public byte Status { get; set; } = 1;
public short SortOrder { get; set; } = 9999;
public byte SourceType { get; set; } = 5;
public int TenantId { get; set; }
public int CreatedById { get; set; }
public DateTime CreatedOn { get; set; }
public int ModifiedById { get; set; }
public DateTime ModifiedOn { get; set; }
}
///
/// Lightweight DTO for list views — no child collections.
/// Used by GetAssessmentAttemptList endpoint.
///
public class AssessmentAttemptListDTO
{
public int AssessmentAttemptId { get; set; }
public int AssessmentId { get; set; }
public string AssessmentTitle { get; set; } = string.Empty;
/// 0=Quiz, 1=PracticalTest, 2=Assignment, 3=Observation, 4=Simulation, 5=Portfolio
public byte AssessmentType { get; set; }
public int EnrollmentId { get; set; }
public int EmployeeId { get; set; }
public string EmployeeName { get; set; } = string.Empty;
public short AttemptNo { get; set; }
public DateTime StartedOn { get; set; }
public DateTime? CompletedOn { get; set; }
public int TotalMarks { get; set; }
public decimal MarksObtained { get; set; }
public decimal ScorePct { get; set; }
/// 0 = No/Pending, 1 = Yes
public byte AttemptIsPassed { get; set; }
public byte Status { get; set; }
public DateTime CreatedOn { get; set; }
}
///
/// Full list DTO — all attempts across all enrollments with complete enrollment context.
/// Used by GetAssessmentAttemptFullList endpoint (no EnrollmentId filter).
///
public class AssessmentAttemptFullListDTO
{
public int AssessmentAttemptId { get; set; }
public int AssessmentId { get; set; }
public string AssessmentTitle { get; set; } = string.Empty;
public byte AssessmentType { get; set; }
public int EnrollmentId { get; set; }
public string? EnrollmentCode { get; set; }
public string? EnrollmentName { get; set; }
public int InstanceId { get; set; }
public string? InstanceCode { get; set; }
public string? InstanceTitle { get; set; }
public int ProgrammeId { get; set; }
public string? ProgrammeCode { get; set; }
public string? ProgrammeTitle { get; set; }
public int EmployeeId { get; set; }
public string? EmployeeCode { get; set; }
public string? EmployeeName { get; set; }
public short AttemptNo { get; set; }
public DateTime StartedOn { get; set; }
public DateTime? CompletedOn { get; set; }
public int TotalMarks { get; set; }
public decimal MarksObtained { get; set; }
public decimal ScorePct { get; set; }
public byte AttemptIsPassed { get; set; }
public int? EvaluatedById { get; set; }
public string? EvaluatedByName { get; set; }
public byte IsLmsSynced { get; set; }
public string? Remarks { get; set; }
public short Version { get; set; }
public byte Status { get; set; }
public short SortOrder { get; set; }
public byte SourceType { get; set; }
public int TenantId { get; set; }
public int CreatedById { get; set; }
public DateTime CreatedOn { get; set; }
public int ModifiedById { get; set; }
public DateTime ModifiedOn { get; set; }
/// Responses still at IsCorrect=-1 (Pending manual evaluation).
public int PendingResponseCount { get; set; }
}
///
/// Minimal DTO for selectlist / picklist dropdowns.
/// Used by GetSelectListAssessmentAttempt endpoint.
///
public class AssessmentAttemptSelectDTO
{
public int Id { get; set; }
public string Code { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
}
///
/// Request DTO for submitting a completed attempt with all responses.
/// Used by SubmitAssessmentAttempt endpoint.
/// Wraps the attempt identity + full response array in one payload.
///
public class SubmitAttemptDTO
{
/// The attempt being submitted.
public int AssessmentAttemptId { get; set; }
public int AssessmentId { get; set; }
public int EnrollmentId { get; set; }
public int EmployeeId { get; set; }
public int TotalMarks { get; set; }
public decimal PassMark { get; set; }
///
/// All per-question responses for this submission.
/// Uses TMSDAL.DTO.AttemptResponse.AttemptResponseDTO.
///
public List Responses { get; set; } = new();
}
}