using System;
using BarContracts.BindingModels;
using BarContracts.ViewModels;
using BarDataModels.Enums;
using BarDataModels.Models;

namespace BarListImplement.Models
{
    public class Order : IOrderModel
    {
        public int Id { get; private set; }

        public int CocktailId { get; private set; }
        public int ClientId { get; private set; }

        public int Count { get; private set; }

        public double Sum { get; private set; }

        public OrderStatus Status { get; private set; } = OrderStatus.Undefined;

        public DateTime DateCreate { get; private set; }

        public DateTime? DateImplement { get; private set; }

        public static Order? Create(OrderBindingModel? Model)
        {
            if (Model is null)
                return null;

            return new Order()
            {
                Id = Model.Id,
                CocktailId = Model.CocktailId,
                ClientId = Model.ClientId,
                Count = Model.Count,
                Sum = Model.Sum,
                Status = Model.Status,
                DateCreate = Model.DateCreate,
                DateImplement = Model.DateImplement
            };
        }

        public void Update(OrderBindingModel? Model)
        {
            if (Model == null)
                return;

            CocktailId = Model.CocktailId;
            Count = Model.Count;
            Sum = Model.Sum;
            Status = Model.Status;
            DateCreate = Model.DateCreate;
            DateImplement = Model.DateImplement;
        }

        public OrderViewModel GetViewModel => new()
        {
            Id = Id,
            CocktailId = CocktailId,
            ClientId = ClientId,
            Count = Count,
            Sum = Sum,
            Status = Status,
            DateCreate = DateCreate,
            DateImplement = DateImplement
        };
    }
}
