using DressAtelierContracts.BindingModels;
using DressAtelierContracts.ViewModels;
using DressAtelierDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DressAtelierFileImplement.Models
{
    public class Client : IClientModel
    {
        public int ID { get; set; }
        public string FullName { get; set; } = string.Empty;

        public string Email { get; set; } = string.Empty;

        public string Password { get; set; } = string.Empty;

        public static Client? Create(ClientBindingModel? model)
        {
            if (model == null)
            {
                return null;
            }
            return new Client()
            {
                ID = model.ID,
                FullName = model.FullName,
                Email = model.Email,
                Password = model.Password
            };
        }

        public static Client? Create(XElement element)
        {
            if (element == null)
            {
                return null;
            }
            return new Client()
            {
                ID = Convert.ToInt32(element.Attribute("ID")!.Value),
                FullName = element.Element("FullName")!.Value,
                Email = element.Element("Email")!.Value,
                Password = element.Element("Password")!.Value
            };
        }

        public void Update(ClientBindingModel? model)
        {
            if (model == null) { return; }
            FullName = model.FullName;
            Email = model.Email;
            Password = model.Password;
        }

        public ClientViewModel GetViewModel => new()
        {
            ID = ID,
            FullName = FullName,
            Email = Email,
            Password = Password
        };

        public XElement GetXElement => new("Client", new XAttribute("ID", ID),
                                                       new XElement("FullName", FullName),
                                                       new XElement("Email", Email),
                                                       new XElement("Password", Password));
    }
}
