using AyCode.Core.Serializers.Attributes;
using AyCode.Core.Serializers.Toons;
using FruitBank.Common.Interfaces;
using LinqToDB.Mapping;
using Mango.Nop.Core.Entities;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations.Schema;

namespace FruitBank.Common.Entities;

[AcBinarySerializable(false, true, false, true, false, false)]
[ToonDescription("Links shipping documents to files with document type", Purpose = "A many-to-many link table that associates general uploaded files with specific shipping documents, assigning a functional context (DocumentType) to each file, such as identifying which PDF is the supplier's invoice versus the packing list")]
[LinqToDB.Mapping.Table(Name = FruitBankConstClient.ShippingDocumentToFilesDbTableName)]
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.ShippingDocumentToFilesDbTableName)]
public sealed class ShippingDocumentToFiles : MgEntityBase, IShippingDocumentToFiles
{
    public int FilesId { get; set; }

    public int ShippingDocumentId { get; set; }

    [ToonDescription(Constraints = "enum-reference: DocumentType")]
    public int DocumentTypeId { get; set; }

    [NotColumn, NotMapped, JsonIgnore, System.Text.Json.Serialization.JsonIgnore]
    [ToonDescription(Purpose = "Enum wrapper", BusinessRule = "get, set => DocumentTypeId")]
    public DocumentType DocumentType
    {
        get => (DocumentType)DocumentTypeId;
        set => DocumentTypeId = (int)value;
    }


    [Association(ThisKey = nameof(FilesId), OtherKey = nameof(Files.Id), CanBeNull = true)]
    public Files? ShippingDocumentFile { get; set; }

    [Association(ThisKey = nameof(ShippingDocumentId), OtherKey = nameof(ShippingDocument.Id), CanBeNull = true)]
    public ShippingDocument? ShippingDocument { get; set; }

    
    [SkipValuesOnUpdate] public DateTime Created { get; set; }
    public DateTime Modified { get; set; }
}