using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using e_suite.Database.Audit.Attributes;
using e_suite.Database.Core.Models;
using Microsoft.EntityFrameworkCore;

namespace e_suite.Database.Core.Tables.Forms;

[DisplayName("Form Template Version")]
[Table("FormTemplateVersions", Schema = "Forms")]
[Index(nameof(TemplateId), nameof(Version), IsUnique = true)]
[Index(nameof(Guid), IsUnique = true)]
public class FormTemplateVersion : IGeneralId, ISoftDeletable
{
    [Key]
    public long Id { get; set; }

    [Required]
    public long TemplateId { get; set; }

    [Required]
    public long Version { get; set; } = 0;

    [AuditName]
    [NotMapped]
    public string DisplayName => $"{Template.Name} V{Version}";

    [Required]
    public string FormDefinition { get; set; } = string.Empty;

    [AuditSoftDelete(true)]
    [Required]
    [DefaultValue(false)]
    public bool Deleted { get; set; } = false;

    [Required]
    public Guid Guid { get; set; } = Guid.NewGuid();

    [AuditLastUpdated]
    public DateTimeOffset LastUpdated { get; set; }

    [AuditParent]
    [ForeignKey(nameof(TemplateId))]
    public virtual FormTemplate Template { get; set; } = null!;
}