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

namespace Tiku.Domain.Catalog;

public sealed class Region : AuditableTenantEntity
{
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Code { get; set; }
    public string? ShortName { get; set; }
    public string? FullName { get; set; }
    public string? Icon { get; set; }
    public string? Pinyin { get; set; }
    public int SortOrder { get; set; }
    public bool IsHot { get; set; }
    public bool IsActive { get; set; } = true;
    public JsonElement Config { get; set; } = JsonDefaults.Object();
}

public sealed class RegionModule : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Type { get; set; }
    public string? Icon { get; set; }
    public string? Color { get; set; }
    public string? TextColor { get; set; }
    public string? Description { get; set; }
    public string? Route { get; set; }
    public int SortOrder { get; set; }
    public bool IsPrimarySchoolModule { get; set; }
    public bool IsActive { get; set; } = true;
}

public sealed class ModuleNode : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public Guid? ModuleId { get; set; }
    public Guid? ParentId { get; set; }
    public string? LegacyId { get; set; }
    public string? LegacyParentId { get; set; }
    public string? LegacyModuleId { get; set; }
    public ModuleNodeType Type { get; set; } = ModuleNodeType.Custom;
    public string Name { get; set; } = string.Empty;
    public string? Path { get; set; }
    public int SortOrder { get; set; }
    public bool IsActive { get; set; } = true;
    public JsonElement Metadata { get; set; } = JsonDefaults.Object();
}

public enum ModuleNodeType
{
    Category,
    Subject,
    Chapter,
    Paper,
    School,
    Major,
    Custom
}

public sealed class School : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public Guid? ModuleId { get; set; }
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? ProfessionalExamDate { get; set; }
    public JsonElement Metadata { get; set; } = JsonDefaults.Object();
}

public sealed class Major : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public Guid? SchoolId { get; set; }
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public string? StudyTips { get; set; }
    public int SortOrder { get; set; }
    public bool IsActive { get; set; } = true;
}

public sealed class Subject : AuditableTenantEntity
{
    public Guid? RegionId { get; set; }
    public Guid? ModuleId { get; set; }
    public Guid? SchoolId { get; set; }
    public Guid? MajorId { get; set; }
    public Guid? NodeId { get; set; }
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public SubjectType? Type { get; set; }
    public JsonElement MajorLegacyIds { get; set; } = JsonDefaults.Array();
    public string? Icon { get; set; }
    public string? Description { get; set; }
    public JsonElement Stats { get; set; } = JsonDefaults.Object();
    public int SortOrder { get; set; }
    public bool IsActive { get; set; } = true;
}

public enum SubjectType
{
    Cultural,
    Professional
}

public sealed class Category : AuditableTenantEntity
{
    public Guid? SubjectId { get; set; }
    public Guid? NodeId { get; set; }
    public string? LegacyId { get; set; }
    public string Name { get; set; } = string.Empty;
    public CategoryType? CategoryType { get; set; }
    public int SortOrder { get; set; }
    public int? SvipQuestionLimit { get; set; }
    public bool IsActive { get; set; } = true;
}

public enum CategoryType
{
    Chapter,
    Paper
}