using System.Text.Json;
using Tiku.Domain.Common;

namespace Tiku.Domain.QuestionBanks;

public sealed class QuestionBank : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public Guid? ContentEntryId { get; set; }
    public string Name { get; set; } = string.Empty;
    public QuestionBankStatus Status { get; set; } = QuestionBankStatus.Active;
    public JsonElement Metadata { get; set; } = JsonDefaults.Object();
}

public enum QuestionBankStatus
{
    Active,
    Archived
}

public sealed class Question : AuditableTenantEntity
{
    public Guid? QuestionBankId { get; set; }
    public Guid? SubjectId { get; set; }
    public Guid? CategoryId { get; set; }
    public Guid? NodeId { get; set; }
    public Guid? EntryId { get; set; }
    public Guid? ContentNodeId { get; set; }
    public Guid? PrimaryCollectionId { get; set; }
    public string? LegacyId { get; set; }
    public string? LegacySubjectId { get; set; }
    public string? LegacyCategoryId { get; set; }
    public string? LegacyNodeId { get; set; }
    public string Type { get; set; } = "choice";
    public string? TypeLabel { get; set; }
    public int? Difficulty { get; set; }
    public JsonElement Tags { get; set; } = JsonDefaults.Array();
    public JsonElement ExamMarkers { get; set; } = JsonDefaults.Object();
    public string? MediaUrl { get; set; }
    public bool HasVideoExplanation { get; set; }
    public QuestionStatus Status { get; set; } = QuestionStatus.Published;
    public Guid? CurrentVersionId { get; set; }
}

public enum QuestionStatus
{
    Draft,
    Published,
    Archived
}

public sealed class QuestionVersion : Entity, ITenantOwned
{
    public Guid TenantId { get; set; }
    public Guid QuestionId { get; set; }
    public int VersionNo { get; set; } = 1;
    public string? Content { get; set; }
    public JsonElement Options { get; set; } = JsonDefaults.Array();
    public int? CorrectOptionIndex { get; set; }
    public JsonElement CorrectOptionIndices { get; set; } = JsonDefaults.Array();
    public string? AnswerText { get; set; }
    public string? Explanation { get; set; }
    public JsonElement SubQuestions { get; set; } = JsonDefaults.Array();
    public string? CodeLang { get; set; }
    public string? CodeTemplate { get; set; }
    public string? SourceHash { get; set; }
    public Guid? CreatedBy { get; set; }
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}
