using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Plugin.Misc.FruitBankPlugin.Services;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc.Routing;

namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;

/// <summary>
/// Represents plugin route provider
/// </summary>
public class RouteProvider : IRouteProvider
{
    /// <summary>
    /// Register routes
    /// </summary>
    /// <param name="endpointRouteBuilder">Route builder</param>
    public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
    {
        endpointRouteBuilder.MapControllerRoute(name: "Plugin.Misc.FruitBankPlugin.Configure",
            pattern: "Admin/FruitBankPlugin/Configure",
            defaults: new { controller = "FruitBankPluginAdmin", action = "Configure", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.List",
            pattern: "Admin/Order/List",
            defaults: new { controller = "CustomOrder", action = "NewList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.OrderList",
            pattern: "Admin/Order/OrderList",
            defaults: new { controller = "CustomOrder", action = "OrderList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.FruitBankOrderList",
            pattern: "Admin/CustomOrder/FruitBankOrderList",
            defaults: new { controller = "CustomOrder", action = "FruitBankOrderList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.UpdateOrderField",
            pattern: "Admin/CustomOrder/UpdateOrderField",
            defaults: new { controller = "CustomOrder", action = "UpdateOrderField", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.Test",
            pattern: "Admin/Order/Test",
            defaults: new { controller = "CustomOrder", action = "Test", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Index",
            pattern: "Admin",
            defaults: new { controller = "CustomDashboard", action = "Index", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.List",
            pattern: "Admin/Shipping/List",
            defaults: new { controller = "Shipping", action = "List", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.ShippingList",
            pattern: "Admin/Shipping/ShippingList",
            defaults: new { controller = "Shipping", action = "ShippingList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Invoices.List",
            pattern: "Admin/Invoices/List",
            defaults: new { controller = "Invoice", action = "List", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.Create",
            pattern: "Admin/Shipping/Create",
            defaults: new { controller = "Shipping", action = "Create", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.Edit",
            pattern: "Admin/Shipping/Edit",
            defaults: new { controller = "Shipping", action = "Edit", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.UploadFile",
            pattern: "Admin/Shipping/UploadFile",
            defaults: new { controller = "Shipping", action = "UploadFile", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.ReloadPartialView",
            pattern: "Admin/Shipping/ReloadPartialView",
            defaults: new { controller = "Shipping", action = "ReloadPartialView", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Shipping.GetShippingDocumentsByShippingId",
            pattern: "Admin/Shipping/GetShippingDocumentsByShippingId",
            defaults: new { controller = "Shipping", action = "GetShippingDocumentsByShippingId", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.Test",
            pattern: "Admin/ManagementPage/Test",
            defaults: new { controller = "ManagementPage", action = "Test", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.GetShippings",
            pattern: "Admin/ManagementPage/GetShippings",
            defaults: new { controller = "ManagementPage", action = "GetShippings", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.LoadPartial",
            pattern: "Admin/ManagementPage/LoadPartial",
            defaults: new { controller = "ManagementPage", action = "LoadPartial", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.GetPartners",
            pattern: "Admin/ManagementPage/GetPartners",
            defaults: new { controller = "ManagementPage", action = "GetPartners", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.LoadChildGrid",
            pattern: "Admin/ManagementPage/LoadChildGrid",
            defaults: new { controller = "ManagementPage", action = "LoadChildGrid", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Products.List",
            pattern: "Admin/Product/List",
            defaults: new { controller = "CustomProduct", action = "List", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Products.ProductList",
            pattern: "Admin/Product/ProductList",
            defaults: new { controller = "CustomProduct", action = "ProductList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Orders.SaveOrderAttributes",
            pattern: "Admin/CustomOrder/SaveOrderAttributes",
            defaults: new { controller = "CustomOrder", action = "SaveOrderAttributes", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Orders.AllowRevision",
            pattern: "Admin/CustomOrder/AllowRevision",
            defaults: new { controller = "CustomOrder", action = "AllowRevision", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Orders.CustomerSearchAutoComplete",
            pattern: "Admin/CustomOrder/CustomerSearchAutoComplete",
            defaults: new { controller = "CustomOrder", action = "CustomerSearchAutoComplete", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Invoice.CreateInvoice",
            pattern: "Admin/Invoice/CreateInvoice",
            defaults: new { controller = "Invoice", action = "CreateInvoice", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.Edit",
            pattern: "Admin/Order/Edit/{id}",
            defaults: new { controller = "CustomOrder", action = "Edit", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.AddProduct",
            pattern: "Admin/CustomOrder/FruitBankAddProductToOrder",
            defaults: new { controller = "CustomOrder", action = "FruitBankAddProductToOrder", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ManagementPage.ProcessShippingDocument",
            pattern: "Admin/ManagamentPage/ProcessShippingDocument/{id}",
            defaults: new { controller = "ManagementPage", action = "ProcessShippingdocument", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.AppDownload",
            pattern: "Admin/AppDownload",
            defaults: new { controller = "AppDownload", action = "Index", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.AppDownload.Download",
            pattern: "Admin/AppDownload/Download/{version}/{fileName}",
            defaults: new { controller = "AppDownload", action = "Download", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.FruitBankAudio",
            pattern: "Admin/VoiceRecorder",
            defaults: new { controller = "FruitBankAudio", action = "VoiceRecorder", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.ExtractText",
            pattern: "Admin/ExtractText",
            defaults: new { controller = "FileManager", action = "ImageTextExtraction", area = AreaNames.ADMIN });

        // ── Customer Credit ──────────────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.CustomerCredit.List",
            pattern: "Admin/CustomerCredit/List",
            defaults: new { controller = "CustomerCredit", action = "List", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.CustomerCredit.CustomerCreditList",
            pattern: "Admin/CustomerCredit/CustomerCreditList",
            defaults: new { controller = "CustomerCredit", action = "CustomerCreditList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.CustomerCredit.UpdateCreditLimit",
            pattern: "Admin/CustomerCredit/UpdateCreditLimit",
            defaults: new { controller = "CustomerCredit", action = "UpdateCreditLimit", area = AreaNames.ADMIN });

        // ── Admin: PreOrder list ───────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.List",
            pattern: "Admin/PreOrders",
            defaults: new { controller = "PreOrderAdmin", action = "List", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.PreOrderList",
            pattern: "Admin/PreOrders/PreOrderList",
            defaults: new { controller = "PreOrderAdmin", action = "PreOrderList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.Detail",
            pattern: "Admin/PreOrders/Detail/{id:int}",
            defaults: new { controller = "PreOrderAdmin", action = "Detail", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.Cancel",
            pattern: "Admin/PreOrders/Cancel/{id:int}",
            defaults: new { controller = "PreOrderAdmin", action = "Cancel", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.CreatePreOrder",
            pattern: "Admin/PreOrders/CreatePreOrder",
            defaults: new { controller = "PreOrderAdmin", action = "CreatePreOrder", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrders.DemandList",
            pattern: "Admin/PreOrders/DemandList",
            defaults: new { controller = "PreOrderAdmin", action = "DemandList", area = AreaNames.ADMIN });

        // ── Admin: PreOrder availability ─────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrderAvailability.Index",
            pattern: "Admin/PreOrderAvailability",
            defaults: new { controller = "PreOrderAvailability", action = "Index", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrderAvailability.ProductList",
            pattern: "Admin/PreOrderAvailability/ProductList",
            defaults: new { controller = "PreOrderAvailability", action = "ProductList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrderAvailability.AvailableTodayList",
            pattern: "Admin/PreOrderAvailability/AvailableTodayList",
            defaults: new { controller = "PreOrderAvailability", action = "AvailableTodayList", area = AreaNames.ADMIN });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrderAvailability.SaveWindow",
            pattern: "Admin/PreOrderAvailability/SaveWindow",
            defaults: new { controller = "PreOrderAvailability", action = "SaveWindow", area = AreaNames.ADMIN });

        // ── Public: Unified Order flow ─────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.Index",
            pattern: "rendeles",
            defaults: new { controller = "Order", action = "Index" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.GetDeliveryDateTime",
            pattern: "rendeles/szallitas-idopont",
            defaults: new { controller = "Order", action = "GetDeliveryDateTime" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.SetDeliveryDateTime",
            pattern: "rendeles/szallitas-idopont-beallitas",
            defaults: new { controller = "Order", action = "SetDeliveryDateTime" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.GetAllProducts",
            pattern: "rendeles/osszes-termek",
            defaults: new { controller = "Order", action = "GetAllProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.GetPreOrderProducts",
            pattern: "rendeles/elozetes-termekek",
            defaults: new { controller = "Order", action = "GetPreOrderProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.SearchProducts",
            pattern: "rendeles/kereses",
            defaults: new { controller = "Order", action = "SearchProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.TranscribeAndSearch",
            pattern: "rendeles/hang",
            defaults: new { controller = "Order", action = "TranscribeAndSearch" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.AddToCart",
            pattern: "rendeles/kosarba",
            defaults: new { controller = "Order", action = "AddToCart" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.GetCartItems",
            pattern: "rendeles/kosar",
            defaults: new { controller = "Order", action = "GetCartItems" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Order.PlacePreOrder",
            pattern: "rendeles/elozetes-leadás",
            defaults: new { controller = "Order", action = "PlacePreOrder" });

        // ── Public: Help page ───────────────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Help.Index",
            pattern: "segitseg",
            defaults: new { controller = "Help", action = "Index" });

        // ── Public: Customer preorder list ───────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.CustomerPreOrder.List",
            pattern: "fiokom/elorerendeles-aim",
            defaults: new { controller = "CustomerPreOrder", action = "List" });

        // ── Public: PreOrder (legacy, kept for backward compat) ───────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrder.Index",
            pattern: "elozetes-rendeles",
            defaults: new { controller = "PreOrder", action = "Index" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrder.GetDeliveryDateTime",
            pattern: "elozetes-rendeles/szallitas-idopont",
            defaults: new { controller = "PreOrder", action = "GetDeliveryDateTime" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrder.SetDeliveryDateTime",
            pattern: "elozetes-rendeles/szallitas-idopont-beallitas",
            defaults: new { controller = "PreOrder", action = "SetDeliveryDateTime" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrder.GetAvailableProducts",
            pattern: "elozetes-rendeles/termekek",
            defaults: new { controller = "PreOrder", action = "GetAvailableProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.PreOrder.PlacePreOrder",
            pattern: "elozetes-rendeles/leadás",
            defaults: new { controller = "PreOrder", action = "PlacePreOrder" });

        // ── Public: Quick Order ──────────────────────────────────────────────
        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.Index",
            pattern: "gyors-rendeles",
            defaults: new { controller = "QuickOrder", action = "Index" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.GetAllProducts",
            pattern: "gyors-rendeles/osszes-termek",
            defaults: new { controller = "QuickOrder", action = "GetAllProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.SearchProducts",
            pattern: "gyors-rendeles/kereses",
            defaults: new { controller = "QuickOrder", action = "SearchProducts" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.TranscribeAndSearch",
            pattern: "gyors-rendeles/hang",
            defaults: new { controller = "QuickOrder", action = "TranscribeAndSearch" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.AddToCart",
            pattern: "gyors-rendeles/kosarba",
            defaults: new { controller = "QuickOrder", action = "AddToCart" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.GetCartItems",
            pattern: "gyors-rendeles/kosar",
            defaults: new { controller = "QuickOrder", action = "GetCartItems" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.SetDeliveryDateTime",
            pattern: "gyors-rendeles/szallitas-idopont",
            defaults: new { controller = "QuickOrder", action = "SetDeliveryDateTime" });

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.QuickOrder.GetDeliveryDateTime",
            pattern: "gyors-rendeles/szallitas-idopont-lekerdezes",
            defaults: new { controller = "QuickOrder", action = "GetDeliveryDateTime" });
    }

    /// <summary>
    /// Gets a priority of route provider
    /// </summary>
    public int Priority => 4000;
}
