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

namespace NB.Chat;

public static class MailBoxFactory
{
    /// <summary>
    /// 创建一个邮件箱
    /// </summary>
    /// <param name="scene"></param>
    /// <param name="sendAccountId"></param>
    /// <param name="mail"></param>
    /// <param name="expireTime"></param>
    /// <param name="accountIds"></param>
    /// <returns></returns>
    public static MailBox Create(Scene scene, long sendAccountId, Mail mail, int expireTime, List<long> accountIds)
    {
        var mailBox = Entity.Create<MailBox>(scene, true, true);
        mailBox.SendAccountId = sendAccountId;
        mailBox.Mail = mail;
        mailBox.ExpireTime = TimeHelper.Now + expireTime;
        mailBox.CreateTime = TimeHelper.Now;
        if (accountIds == null || accountIds.Count <= 0)
        {
            return mailBox;
        }

        foreach (var accountId in accountIds)
        {
            mailBox.AccountId.Add(accountId);
        }

        return mailBox;
    }

    /// <summary>
    /// 创建一个邮件箱
    /// </summary>
    /// <param name="scene"></param>
    /// <param name="sendAccountId"></param>
    /// <param name="expireTime"></param>
    /// <param name="accountIds"></param>
    /// <param name="content"></param>
    /// <param name="items"></param>
    /// <returns></returns>
    public static MailBox Create(Scene scene, long sendAccountId, int expireTime, List<long> accountIds,
        string content, List<AwardItem> items = null)
    {
        var mail = MailFactory.Create(scene, content, items);
        return Create(scene, sendAccountId, mail, expireTime, accountIds);
    }
}