using Jiaowu.Api.Domain.Common;
using Jiaowu.Api.Domain.Identity;

namespace Jiaowu.Api.Domain.Academic;

public sealed class OfficialDocument : EntityBase
{
    public required string DocumentNumber { get; set; }
    public required string VerificationCodeHash { get; set; }
    public OfficialDocumentType Type { get; set; }
    public OfficialDocumentStatus Status { get; set; } = OfficialDocumentStatus.Valid;
    public Guid StudentId { get; set; }
    public Student? Student { get; set; }
    public Guid IssuedByUserId { get; set; }
    public ApplicationUser? IssuedByUser { get; set; }
    public DateTime IssuedAt { get; set; } = DateTime.UtcNow;
    public string? Purpose { get; set; }
    public required string SnapshotJson { get; set; }
    public required byte[] PdfContent { get; set; }
    public required string PdfSha256 { get; set; }
    public DateTime? InvalidatedAt { get; set; }
    public Guid? InvalidatedByUserId { get; set; }
    public ApplicationUser? InvalidatedByUser { get; set; }
    public string? InvalidationReason { get; set; }
    public Guid? ReissuedFromDocumentId { get; set; }
    public OfficialDocument? ReissuedFromDocument { get; set; }
    public ICollection<OfficialDocumentDownload> Downloads { get; set; } = [];
}

public sealed class OfficialDocumentDownload : EntityBase
{
    public Guid OfficialDocumentId { get; set; }
    public OfficialDocument? OfficialDocument { get; set; }
    public Guid DownloadedByUserId { get; set; }
    public ApplicationUser? DownloadedByUser { get; set; }
    public string? IpAddress { get; set; }
    public string? UserAgent { get; set; }
}

public enum OfficialDocumentType
{
    Transcript = 1,
    StudentStatusCertificate = 2
}

public enum OfficialDocumentStatus
{
    Valid = 1,
    Invalidated = 2,
    Superseded = 3
}
