using Fantasy;
using Fantasy.Entitas.Interface;
using NB.Game;

namespace NB.Chat;

public class MailDestroySystem : DestroySystem<Mail>
{
    protected override void Destroy(Mail self)
    {
        self.OwnerId = 0;
        self.Sender = 0;
        self.Content = string.Empty;
        self.ExpireTime = 0;
        self.CreateTime = 0;
        self.State = MailState.None;
        self.MailType = MailType.None;
        foreach (var item in self.Items)
        {
            item.Dispose();
        }

        self.Items.Clear();
    }
}

public static class MailSystem
{
    public static MailInfo ToMailInfo(this Mail mail)
    {
        return new MailInfo()
        {
            Id = mail.Id,
            Content = mail.Content,
            CreateTime = mail.CreateTime,
            MailState = (int)mail.State,
            MailType = (int)mail.MailType,
            Items = mail.Items.ToAwardInfo()
        };
    }

    public static List<MailInfo> ToMailInfo(this List<Mail> mails)
    {
        var list = new List<MailInfo>();
        foreach (var mail in mails)
        {
            list.Add(mail.ToMailInfo());
        }

        return list;
    }
}