using AutoMapper;
using Lada.Framework.Data.Domains.OrderBusiness;
using Ladaer.BackEnd.Infrastructures.DTO.Items.OrderBusiness;
using Ladaer.BackEnd.Infrastructures.DTO.Models.OrderBusiness;
using Ladaer.BackEnd.Infrastructures.DTO;

namespace Ladaer.BackEnd.Infrastructures.DTO.Profiles
{
    public class OrderBusinessMappingProfile : Profile
    {
        public OrderBusinessMappingProfile()
        {
            // OrderFailReason mappings
            CreateMap<OrderFailReason, OrderFailReasonItem>()
                .ForMember(dest => dest.TypeName, opt => opt.MapFrom(src =>
                    src.Type == OrderFailReasonType.Pickup ? "Lấy hàng" :
                    src.Type == OrderFailReasonType.Delivery ? "Giao hàng" :
                    src.Type == OrderFailReasonType.Both ? "Cả hai" : ""));

            CreateMap<OrderFailReasonModel, OrderFailReason>();
            CreateMap<OrderFailReason, OrderFailReasonModel>();
        }
    }

    public static class OrderBusinessMappingExtensions
    {
        public static OrderFailReasonItem ToItem(this OrderFailReason entity)
            => entity.MapTo<OrderFailReason, OrderFailReasonItem>();

        public static OrderFailReason ToEntity(this OrderFailReasonModel model)
            => model.MapTo<OrderFailReasonModel, OrderFailReason>();

        public static OrderFailReasonModel ToModel(this OrderFailReason entity)
            => entity.MapTo<OrderFailReason, OrderFailReasonModel>();
    }
}
