using Fantasy;
using Fantasy.Entitas;
using Fantasy.Helper;
using Fantasy.Serialize;
using NB.Game;

namespace NB.Chat;

public static class MailFactory
{
    private static readonly ISerialize _serializer = SerializerManager.GetSerializer(FantasySerializerType.Bson);

    public static Mail Create(Scene scene,  string content, List<AwardItem> items = null)
    {
        var mail = Entity.Create<Mail>(scene, true, true);
        mail.Content = content;
        mail.State = MailState.Unread;
        mail.CreateTime = TimeHelper.Now;
        
        if (items != null && items.Count > 0)
        {
            foreach (var item in items)
            {
                mail.Items.Add(_serializer.Clone(item));
            }
        }
        
        return mail;
    }
}