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 e_suite.Database.Core.Tables.CustomFields;
using Microsoft.EntityFrameworkCore;

namespace e_suite.Database.Core.Tables.Forms;

[DisplayName("Form Field Instance")]
[Table("FormFieldInstances", Schema = "Forms")]
[Index(nameof(Guid), IsUnique = true)]
[Index(nameof(FormInstanceId), nameof(CustomFieldId), nameof(Index), IsUnique = true)]
public class FormFieldInstance : IGeneralId, ICustomFieldValue
{
    [Key]
    public long Id { get; set; }

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

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

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

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

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

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

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

    [AuditParent]
    [ForeignKey(nameof(FormInstanceId))]
    public virtual FormInstance FormInstance { get; set; } = null!;

    [ForeignKey(nameof(CustomFieldId))]
    public CustomField CustomField { get; set; } = null!;
}