package server

import (
	"catalogue.midpdsa.com/src/controllers"
	"catalogue.midpdsa.com/src/middleware"
	"github.com/gin-gonic/gin"
)

func SetupPanelCRUDRoutes(
	r *gin.Engine,
	shockBrandCtrl *controllers.ShockBrandController,
	brakeBrandCtrl *controllers.BrakeBrandController,
	diskBrandCtrl *controllers.DiskBrandController,
	strutBrandCtrl *controllers.StrutBrandController,
	legBrandCtrl *controllers.LegBrandController,
	brakeBrandSpecsCtrl *controllers.BrakeBrandSpecsController,
	shockBrandSpecsCtrl *controllers.ShockBrandSpecsController,
	diskBrandSpecsCtrl *controllers.DiskBrandSpecsController,
	strutBrandSpecsCtrl *controllers.StrutBrandSpecsController,
	legBrandSpecsCtrl *controllers.LegBrandSpecsController,
	brakeStockCtrl *controllers.BrakeStockController,
	shockStockCtrl *controllers.ShockStockController,
	diskStockCtrl *controllers.DiskStockController,
	vehicleBrandCtrl *controllers.VehicleBrandController,
	vehicleTypeCtrl *controllers.VehicleTypeController,
	vehicleModelYearCtrl *controllers.VehicleModelYearController,
	extraTypeProductCharsCtrl *controllers.ExtraTypeProductCaracteristicsController,
	extraTypeBrandCtrl *controllers.ExtraTypeBrandController,
	extraTypeProductCtrl *controllers.ExtraTypeProductController,
	extraProductStockCtrl *controllers.ExtraProductStockController,
) {
	panel := r.Group("/panel")
	protected := panel.Group("")
	protected.Use(middleware.AuthMiddleware())
	{
		// Brands (full CRUD)
		brandTypes := []struct {
			prefix  string
			list    func(*gin.Context)
			getByID func(*gin.Context)
			create  func(*gin.Context)
			update  func(*gin.Context)
			delete  func(*gin.Context)
		}{
			{"shock", shockBrandCtrl.GetShockBrands, shockBrandCtrl.GetShockBrandById, shockBrandCtrl.CreateShockBrand, shockBrandCtrl.UpdateShockBrand, shockBrandCtrl.DeleteShockBrand},
			{"brake", brakeBrandCtrl.GetBrakeBrands, brakeBrandCtrl.GetBrakeBrandById, brakeBrandCtrl.CreateBrakeBrand, brakeBrandCtrl.UpdateBrakeBrand, brakeBrandCtrl.DeleteBrakeBrand},
			{"disk", diskBrandCtrl.GetDiskBrands, diskBrandCtrl.GetDiskBrandById, diskBrandCtrl.CreateDiskBrand, diskBrandCtrl.UpdateDiskBrand, diskBrandCtrl.DeleteDiskBrand},
			{"strut", strutBrandCtrl.GetStrutBrands, strutBrandCtrl.GetStrutBrandById, strutBrandCtrl.CreateStrutBrand, strutBrandCtrl.UpdateStrutBrand, strutBrandCtrl.DeleteStrutBrand},
			{"leg", legBrandCtrl.GetLegBrands, legBrandCtrl.GetLegBrandById, legBrandCtrl.CreateLegBrand, legBrandCtrl.UpdateLegBrand, legBrandCtrl.DeleteLegBrand},
		}
		for _, b := range brandTypes {
			protected.GET("/"+b.prefix+"-brands", b.list)
			protected.GET("/"+b.prefix+"-brands/:id", b.getByID)
			protected.POST("/"+b.prefix+"-brands", b.create)
			protected.PUT("/"+b.prefix+"-brands/:id", b.update)
			protected.DELETE("/"+b.prefix+"-brands/:id", b.delete)
		}

		// Specs (full CRUD)
		specTypes := []struct {
			prefix  string
			list    func(*gin.Context)
			getByID func(*gin.Context)
			create  func(*gin.Context)
			update  func(*gin.Context)
			delete  func(*gin.Context)
		}{
			{"brake", brakeBrandSpecsCtrl.ListBrakeBrandSpecs, brakeBrandSpecsCtrl.GetBrakeBrandSpecsById, brakeBrandSpecsCtrl.CreateBrakeBrandSpec, brakeBrandSpecsCtrl.UpdateBrakeBrandSpec, brakeBrandSpecsCtrl.DeleteBrakeBrandSpec},
			{"shock", shockBrandSpecsCtrl.ListShockBrandSpecs, shockBrandSpecsCtrl.GetShockBrandSpecsById, shockBrandSpecsCtrl.CreateShockBrandSpec, shockBrandSpecsCtrl.UpdateShockBrandSpec, shockBrandSpecsCtrl.DeleteShockBrandSpec},
			{"disk", diskBrandSpecsCtrl.ListDiskBrandSpecs, diskBrandSpecsCtrl.GetDiskBrandSpecsById, diskBrandSpecsCtrl.CreateDiskBrandSpec, diskBrandSpecsCtrl.UpdateDiskBrandSpec, diskBrandSpecsCtrl.DeleteDiskBrandSpec},
			{"strut", strutBrandSpecsCtrl.ListStrutBrandSpecs, strutBrandSpecsCtrl.GetStrutBrandSpecsById, strutBrandSpecsCtrl.CreateStrutBrandSpec, strutBrandSpecsCtrl.UpdateStrutBrandSpec, strutBrandSpecsCtrl.DeleteStrutBrandSpec},
			{"leg", legBrandSpecsCtrl.ListLegBrandSpecs, legBrandSpecsCtrl.GetLegBrandSpecsById, legBrandSpecsCtrl.CreateLegBrandSpec, legBrandSpecsCtrl.UpdateLegBrandSpec, legBrandSpecsCtrl.DeleteLegBrandSpec},
		}
		for _, s := range specTypes {
			protected.GET("/"+s.prefix+"-brand-specs", s.list)
			protected.GET("/"+s.prefix+"-brand-specs/:id", s.getByID)
			protected.POST("/"+s.prefix+"-brand-specs", s.create)
			protected.PUT("/"+s.prefix+"-brand-specs/:id", s.update)
			protected.DELETE("/"+s.prefix+"-brand-specs/:id", s.delete)
		}

		// Stocks (full CRUD)
		protected.GET("/brake-stocks", brakeStockCtrl.ListBrakeStocks)
		protected.GET("/brake-stocks/:id", brakeStockCtrl.GetBrakeStockById)
		protected.POST("/brake-stocks", brakeStockCtrl.CreateBrakeStock)
		protected.PUT("/brake-stocks/:id", brakeStockCtrl.UpdateBrakeStock)
		protected.DELETE("/brake-stocks/:id", brakeStockCtrl.DeleteBrakeStock)

		protected.GET("/shock-stocks", shockStockCtrl.GetShockStocks)
		protected.GET("/shock-stocks/:id", shockStockCtrl.GetShockStockById)
		protected.POST("/shock-stocks", shockStockCtrl.CreateShockStock)
		protected.PUT("/shock-stocks/:id", shockStockCtrl.UpdateShockStock)
		protected.DELETE("/shock-stocks/:id", shockStockCtrl.DeleteShockStock)

		protected.GET("/disk-stocks", diskStockCtrl.GetDiskStocks)
		protected.GET("/disk-stocks/:id", diskStockCtrl.GetDiskStockById)
		protected.POST("/disk-stocks", diskStockCtrl.CreateDiskStock)
		protected.PUT("/disk-stocks/:id", diskStockCtrl.UpdateDiskStock)
		protected.DELETE("/disk-stocks/:id", diskStockCtrl.DeleteDiskStock)

		// Vehicles (full CRUD)
		protected.GET("/vehicle-brands", vehicleBrandCtrl.GetVehicleBrands)
		protected.GET("/vehicle-brands/:id", vehicleBrandCtrl.GetVehicleBrandById)
		protected.POST("/vehicle-brands", vehicleBrandCtrl.CreateVehicleBrand)
		protected.PUT("/vehicle-brands/:id", vehicleBrandCtrl.UpdateVehicleBrand)
		protected.DELETE("/vehicle-brands/:id", vehicleBrandCtrl.DeleteVehicleBrand)

		protected.GET("/vehicle-types", vehicleTypeCtrl.GetVehicleTypes)
		protected.GET("/vehicle-types/:id", vehicleTypeCtrl.GetVehicleTypeById)
		protected.POST("/vehicle-types", vehicleTypeCtrl.CreateVehicleType)
		protected.PUT("/vehicle-types/:id", vehicleTypeCtrl.UpdateVehicleType)
		protected.DELETE("/vehicle-types/:id", vehicleTypeCtrl.DeleteVehicleType)

		protected.GET("/vehicle-model-years", vehicleModelYearCtrl.GetVehicleModelYears)
		protected.GET("/vehicle-model-years/:id", vehicleModelYearCtrl.GetVehicleModelYearById)
		protected.POST("/vehicle-model-years", vehicleModelYearCtrl.CreateVehicleModelYear)
		protected.PUT("/vehicle-model-years/:id", vehicleModelYearCtrl.UpdateVehicleModelYear)
		protected.DELETE("/vehicle-model-years/:id", vehicleModelYearCtrl.DeleteVehicleModelYear)

		// Extras (full CRUD)
		protected.GET("/extra-type-product-caracteristics", extraTypeProductCharsCtrl.ListExtraTypeProductCaracteristics)
		protected.GET("/extra-type-product-caracteristics/:id", extraTypeProductCharsCtrl.GetExtraTypeProductCaracteristics)
		protected.POST("/extra-type-product-caracteristics", extraTypeProductCharsCtrl.CreateExtraTypeProductCaracteristic)
		protected.PUT("/extra-type-product-caracteristics/:id", extraTypeProductCharsCtrl.UpdateExtraTypeProductCaracteristic)
		protected.DELETE("/extra-type-product-caracteristics/:id", extraTypeProductCharsCtrl.DeleteExtraTypeProductCaracteristic)

		protected.GET("/extra-type-brand", extraTypeBrandCtrl.ListExtraTypeBrands)
		protected.GET("/extra-type-brand/:id", extraTypeBrandCtrl.GetExtraTypeBrand)
		protected.POST("/extra-type-brand", extraTypeBrandCtrl.CreateExtraTypeBrand)
		protected.PUT("/extra-type-brand/:id", extraTypeBrandCtrl.UpdateExtraTypeBrand)
		protected.DELETE("/extra-type-brand/:id", extraTypeBrandCtrl.DeleteExtraTypeBrand)

		protected.GET("/extra-type-product", extraTypeProductCtrl.ListExtraTypeProducts)
		protected.GET("/extra-type-product/:id", extraTypeProductCtrl.GetExtraTypeProduct)
		protected.POST("/extra-type-product", extraTypeProductCtrl.CreateExtraTypeProduct)
		protected.PUT("/extra-type-product/:id", extraTypeProductCtrl.UpdateExtraTypeProduct)
		protected.DELETE("/extra-type-product/:id", extraTypeProductCtrl.DeleteExtraTypeProduct)

		protected.GET("/extra-product-stocks", extraProductStockCtrl.ListExtraProductStocks)
		protected.GET("/extra-product-stocks/:id", extraProductStockCtrl.GetExtraProductStocks)
		protected.POST("/extra-product-stocks", extraProductStockCtrl.CreateExtraProductStock)
		protected.PUT("/extra-product-stocks/:id", extraProductStockCtrl.UpdateExtraProductStock)
		protected.DELETE("/extra-product-stocks/:id", extraProductStockCtrl.DeleteExtraProductStock)
	}
}
