using AutoMapper;
using Bp.Inventory.Domain.Batches;
using Bp.Sync.Domain.Elastics.FcBusinesses;
using Bp.Sync.Domain.Elastics.FcBusinesses.Bills;
using Bp.Sync.Domain.Elastics.FcBusinesses.Products;
using Bp.Sync.Domain.Elastics.FcBusinesses.UnitExchanges;
using Bp.Sync.Domain.Elastics.FcCustomers.Customers;
using Bp.Sync.Domain.Elastics.Finances;
using Bp.Sync.Domain.Elastics.Inventories;
using Bp.Sync.Domain.Elastics.Inventories.Accounts;
using Bp.Sync.Domain.Elastics.Inventories.Bills;
using Bp.Sync.Domain.Elastics.Inventories.Categories;
using Bp.Sync.Domain.Elastics.Inventories.Customers;
using Bp.Sync.Domain.Elastics.Inventories.Generals;
using Bp.Sync.Domain.Elastics.Inventories.Orders;
using Bp.Sync.Domain.Elastics.Inventories.Products;
using Bp.Sync.Domain.Elastics.Inventories.Suppliers;
using Bp.Sync.Domain.Elastics.Inventories.Units;
using Bp.Sync.Domain.Entities.FcBusinesses;
using Bp.Sync.Domain.Entities.FcCustomers.Customers;
using Bp.Sync.Domain.Entities.Finances;
using Bp.Sync.Domain.Entities.Inventories;
using Bp.Sync.Domain.Entities.Inventories.Accounts;
using Bp.Sync.Domain.Entities.Inventories.Bills;
using Bp.Sync.Domain.Entities.Inventories.Branches;
using Bp.Sync.Domain.Entities.Inventories.Categories;
using Bp.Sync.Domain.Entities.Inventories.Customers;
using Bp.Sync.Domain.Entities.Inventories.Generals;
using Bp.Sync.Domain.Entities.Inventories.Invoices;
using Bp.Sync.Domain.Entities.Inventories.Orders;
using Bp.Sync.Domain.Entities.Inventories.Products;
using Bp.Sync.Domain.Entities.Inventories.Reasons;
using Bp.Sync.Domain.Entities.Inventories.Suppliers;
using Bp.Sync.Domain.Entities.Inventories.Units;

namespace Bp.Sync.BackEnd.Infrastructure.Mappings
{
    public class AutoMapperConfig
    {
        #region Properties
        private static MapperConfiguration _mapperConfiguration;
        private static IMapper _mapper;

        /// <summary>
        /// Mapper
        /// </summary>
        public static IMapper Mapper => _mapper;

        /// <summary>
        /// Mapper configuration
        /// </summary>
        public static MapperConfiguration MapperConfiguration => _mapperConfiguration;
        #endregion

        public static void Init()
        {
            try
            {
                _mapperConfiguration = new MapperConfiguration(cfg =>
                {
                    //inventory
                    cfg.CreateMap<Transaction, TransactionElastic>();
                    cfg.CreateMap<Bill, BillElastic>();
                    cfg.CreateMap<OutboundBill, OutboundBillElastic>();
                    cfg.CreateMap<InboundBill, InboundBillElastic>();
                    cfg.CreateMap<InventoryBill, InventoryBillElastic>();
                    cfg.CreateMap<Invoice, InvoiceElastic>();
                    cfg.CreateMap<Product, ProductElastic>();
                    cfg.CreateMap<ProductInvoice, ProductInvoiceElastic>();
                    cfg.CreateMap<ProductInventory, ProductInventoryElastic>();
                    cfg.CreateMap<Order, OrderElastic>();
                    cfg.CreateMap<ProductOrder, ProductOrderElastic>();
                    cfg.CreateMap<RetailBill, RetailBillElastic>();
                    cfg.CreateMap<Branch, BranchElastic>();
                    cfg.CreateMap<Unit, UnitElastic>();
                    cfg.CreateMap<ProductUnit, ProductUnitElastic>();
                    cfg.CreateMap<Customer, CustomerElastic>();
                    cfg.CreateMap<Supplier, SupplierElastic>();
                    cfg.CreateMap<Batch, BatchElastic>();
                    cfg.CreateMap<ProductGroup, ProductGroupElastic>();
                    cfg.CreateMap<ProductType, ProductTypeElastic>();
                    cfg.CreateMap<ProductBill, ProductBillElastic>();
                    cfg.CreateMap<Debt, DebtElastic>();
                    cfg.CreateMap<GeneralLedger, GeneralLedgerElastic>();
                    cfg.CreateMap<Account, AccountElastic>();
                    cfg.CreateMap<Reason, ReasonElastic>();

                    //fc
                    cfg.CreateMap<RetailStatistic, RetailStatisticElastic>();
                    cfg.CreateMap<InboundStatistic, InboundStatisticElastic>();
                    cfg.CreateMap<OutboundStatistic, OutboundStatisticElastic>();
                    cfg.CreateMap<FcCustomer, FcCustomerElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.Bills.InboundBill, FcInboundBillElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.Bills.OutboundBill, FcOutboundBillElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.Bills.ReceiptBill, FcReceiptBillElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.Products.ProductStorage, FcProductStorageElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.Products.ProductShipment, FcProductShipmentElastic>();
                    cfg.CreateMap<Domain.Entities.FcBusinesses.UnitExchanges.UnitExchange, FcUnitExchangeElastic>();

                });

                _mapper = _mapperConfiguration.CreateMapper();
            }
            catch
            {
                // ignored
            }
        }
    }
}
