using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc.Routing;

namespace Nop.Plugin.Misc.AuctionPlugin.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)
        {
            //config
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.ConfigurationRouteName,
            pattern: "Admin/AuctionPlugin/Configure",
            defaults: new { controller = "AuctionPluginAdmin", action = "Configure", area = AreaNames.ADMIN });

            //announcement admin
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AnnouncementRouteName,
            pattern: "Admin/Announcement/GetAnnouncementViewModel",
            defaults: new { controller = "Announcement", action = "GetAnnouncementViewModel" });

            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AnnouncementListRouteName,
            pattern: "Admin/Announcement/AnnouncementList",
            defaults: new { controller = "Announcement", action = "AnnouncementList" });

            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AuctionRouteName,
            pattern: "Admin/AuctionPlugin/GetAuctionViewModel",
            defaults: new { controller = "AuctionPluginAdmin", action = "GetAuctionViewModel" });

            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AuctionListRouteName,
            pattern: "Admin/AuctionPlugin/AuctionList",
            defaults: new { controller = "AuctionPluginAdmin", action = "AuctionList" });

            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.GetAuctionByIdRouteName,
            pattern: "Admin/AuctionPlugin/GetAuctionById/{auctionId}",
            defaults: new { controller = "AuctionPluginAdmin", action = "GetAuctionById" });
            
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.SaveAuctionRouteName,
            pattern: "Admin/AuctionPlugin/SaveAuction",
            defaults: new { controller = "AuctionPluginAdmin", action = "SaveAuction" });

            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.TestPageRouteName,
            pattern: "Admin/Auction/TestPage",
            defaults: new { controller = "AuctionPluginAdmin", action = "TestPage" });
            
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.BidNotificationRouteName,
            pattern: "Admin/Announcement/SendBidNotificationViewModel",
            defaults: new { controller = "Announcement", action = "SendBidNotificationViewModel" });
            
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.RefreshAuctionWidgetRouteName,
            pattern: "Auction/RefreshAuctionWidget",
            defaults: new { controller = "Auction", action = "RefreshAuctionWidget" });
            
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AssignProductToAuction,
            pattern: "Admin/Auction/AssignProductToAuction",
            defaults: new { controller = "AuctionPluginAdmin", action = "AssignProductToAuction" });
            
            endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.LiveScreenRouteName,
            pattern: "Auction/LiveScreen/{auctionId}",
            defaults: new { controller = "Auction", action = "LiveScreen" });

        }

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