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.MapHub<FruitBankHub>("/fbhub");//.RequireCors("AllowBlazorClient");

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Order.List",
            pattern: "Admin/Order/List",
            defaults: new { controller = "CustomOrder", action = "List", area = AreaNames.ADMIN }
            //constraints: new { 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.Test",
            pattern: "Admin/Order/Test",
            defaults: new { controller = "CustomOrder", action = "Test", area = AreaNames.ADMIN }
            //constraints: new { area = AreaNames.ADMIN }
        );

        endpointRouteBuilder.MapControllerRoute(
            name: "Plugin.FruitBank.Admin.Index",
            pattern: "Admin",
            defaults: new { controller = "CustomDashboard", action = "Index", area = AreaNames.ADMIN }
            //constraints: new { 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 });
    }

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