using BankContracts.BindingModels;
using BankContracts.ViewModels;
using BankDataModels;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;

namespace BankDatabaseImplement.Models
{
    public class Payment : IPaymentModel
    {
        [Required]
        public int OperationByPurchaseId { get; private set; }

        [Required]
        public DateOnly Date { get; private set; }

        [Required]
        public double PaidPrice { get; private set; }

        public int Id { get; private set; }

        [Required]
        public OperationByPurchase? OperationByPurchase { get; private set; }

        public static Payment Create(PaymentBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Payment()
            {

                Date = model.Date,
                PaidPrice = model.PaidPrice,
                Id = model.Id,
                OperationByPurchaseId = model.OperationByPurchaseId,
            };
        }
        public PaymentViewModel GetViewModel => new()
        {
            Operation = OperationByPurchase?.Operation?.GetViewModel,
            OperationByPurchase = OperationByPurchase,
            FullPrice = OperationByPurchase?.Operation?.Price ?? -1,
            Date = Date,
            PaidPrice = PaidPrice,
            Id = Id,
            OperationByPurchaseId = OperationByPurchaseId,
        };
    }
}
