using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users;
using TIAM.Entities.Drivers;
using TIAM.Entities.Products;
using TIAM.Entities.Transfers;

namespace TIAM.Entities.Users;

[Table("UserProductMapping")]
public class UserProductMapping : IEntityGuid, IUserRelation, IProductRelation, ITimeStampInfo
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public Guid Id { get; set; }
    public Guid UserId { get; set; }
    public Guid ProductId { get; set; }

    public virtual User User { get; set; }
    public virtual Product Product { get; set; }
    public virtual List<Transfer>? Transfers { get; set; }

    public int Permissions { get; set; } = 1;
    public bool IsAdmin { get; set; }

    //[JsonIgnore]
    //private string? JsonDetails { get; set; }

    //[Column("JsonDetailModel")]
    public UserProductJsonDetailModel? JsonDetailModel { get; set; } = null;

    public DateTime Created { get; set; }
    public DateTime Modified { get; set; }

    public UserProductMapping()
    { }

    public UserProductMapping(Guid userId, Guid productId) : this(Guid.NewGuid(), userId, productId)
    { }

    public UserProductMapping(Guid id, Guid userId, Guid productId) : this(id, userId, productId, 1)
    { }

    public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions) : this(id, userId, productId, permissions, null)
    { }

    public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions, UserProductJsonDetailModel? toJsonDetailModel) : this()
    {
        Id = id;
        UserId = userId;
        ProductId = productId;

        Permissions = permissions;
        JsonDetailModel = toJsonDetailModel;
    }
}