using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Web.Framework.Mvc.ModelBinding;

namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;

public class AuctionDto : IAuctionDto
{
    public int Id { get; set; }
    
    public int? CategoryId { get; set; }
    
    [NopResourceDisplayName("Name")]
    public string AuctionName { get; set; }

    public AuctionType AuctionType { get; set; }
    public DateTime StartDateUtc { get; set; }
    public DateTime? EndDateUtc { get; set; }
    public bool Closed { get; set; }

    public List<ProductToAuctionDto> ProductToAuctionDtos { get; } = [];

    public AuctionDto()
    {
    }

    public AuctionDto(Auction auction)
    {
        if (auction == null) return;

        Id = auction.Id;
        CategoryId = auction.CategoryId;
        AuctionName = auction.AuctionName;
        AuctionType = auction.AuctionType;
        StartDateUtc = auction.StartDateUtc;
        EndDateUtc = auction.EndDateUtc;
        Closed = auction.Closed;
    }

    public Auction CreateMainEntity()
    {
        var mainEntity = Activator.CreateInstance<Auction>();

        mainEntity.Id = Id;
        mainEntity.AuctionName = AuctionName;
        mainEntity.AuctionType = AuctionType;
        mainEntity.CategoryId = CategoryId;
        mainEntity.StartDateUtc = StartDateUtc;
        mainEntity.EndDateUtc = EndDateUtc;
        mainEntity.Closed = Closed;

        return mainEntity;
    }
}