using System.Xml.Linq;

namespace Billing.Models
{
    public class Account : BaseModel
    {
        public int Id { get; set; }
        public string Icon { get; set; } = ICON_DEFAULT;
        public AccountCategory Category { get; set; }
        public string Name { get; set; }
        public decimal Balance { get; set; }
        public string Memo { get; set; }

        public override void OnXmlDeserialize(XElement node)
        {
            Id = Read(node, nameof(Id), 0);
            Icon = Read(node, nameof(Icon), ICON_DEFAULT);
            Category = (AccountCategory)Read(node, nameof(Category), 0);
            Name = Read(node, nameof(Name), string.Empty);
            Balance = Read(node, nameof(Balance), 0m);
            Memo = Read(node, nameof(Memo), null);
        }

        public override void OnXmlSerialize(XElement node)
        {
            Write(node, nameof(Id), Id);
            Write(node, nameof(Icon), Icon);
            Write(node, nameof(Category), (int)Category);
            Write(node, nameof(Name), Name);
            Write(node, nameof(Balance), Balance);
            Write(node, nameof(Memo), Memo);
        }
    }

    public enum AccountCategory
    {
        Cash = 0,
        CreditCard,
        DebitCard,
        ElecAccount
    }
}