const express = require("express");
const router = express.Router();

const Auth = require("../middleware/Auth");
const adminController = require("../controller/admin");
const categoryController = require("../controller/category");
const productController = require("../controller/product");
const reviewController = require("../controller/review");
const orderController = require("../controller/order");
const couponController = require("../controller/coupon");

// Admin Auth Routes
router.post("/admin/signup", adminController.signup);
router.post("/admin/verifyOTP", adminController.verifyOTP);
router.post("/admin/login", adminController.login);
router.post("/admin/updateAdmin", Auth.uploadAdmin.single("adminProfile"), adminController.updateAdmin)
router.get("/admin/adminProfile", adminController.getAdminProfile);
router.post("/admin/forgetPassword", adminController.forgetPassword);
router.post("/admin/verifyPasswordOTP", adminController.OTPForPassword);
router.post("/admin/resetPassword", adminController.resetPassword);
router.post("/admin/deleteAdmin", adminController.deleteAdmin);

// Admin Shop Routes
router.post("/admin/createShop", Auth.uploadShop.single("shopImage"), adminController.addShop);
router.get("/admin/getShopByAdminId", adminController.getShopAdminId);
router.post("/admin/updateShop", Auth.uploadShop.single("shopImage"), adminController.updateShop);
router.post("/admin/deleteShop", adminController.deleteShop);
router.get("/user/getAllShops", adminController.getAllShops);
router.get("/user/nearbyShops", adminController.nearByShops);
router.get("/user/getShopById", adminController.getShopById);

// Admin Category Routes
router.post("/admin/category", categoryController.addCaregory);
router.get("/admin/getAllCategories", categoryController.getAllCategories);
router.get("/admin/AllCategoriesByAdmin", categoryController.getCategoriesByAdminId);
router.get("/admin/getCategoryById", categoryController.getCategoryById);
router.post("/admin/deleteCategory", categoryController.deleteCategory);

//Admin Products Routes
router.post("/admin/addProduct", Auth.uploadProduct.array("ProductImages", 5), productController.addProduct);
router.get("/admin/getProductById", productController.getProductById);
router.post("/admin/addVariant", Auth.uploadProduct.array("ProductImages", 5), productController.addVariants);
router.get("/admin/getAllProducts", productController.getAllProductsByAdminId);
router.get("/user/getAllProducts", productController.getAllProductsByAdminId);
router.get("/admin/productsByCategory", productController.getProductsByCategory);
router.post("/admin/updateProduct", Auth.uploadProduct.array("ProductImages", 5), productController.updateProduct);
router.post('/admin/deleteProduct', productController.deleteProduct);

// All Order Routes
router.post("/user/createOrder", orderController.createOrder);
router.get("/user/allOrdersByUser", orderController.getAllordersByUserId);
router.post("/user/updateOrder", orderController.updateOrder);
router.get("/user/getOrderById", orderController.getOrderById);
router.get("/admin/allOrdersByAdmin", orderController.getAllOrdersByAdminId);
router.get("/admin/getOrderById", orderController.getOrderById);
router.post("/admin/udpateOrderStatus", orderController.updateOrderStatus);
router.post("/user/deleteOrder", orderController.deleteOrder);

// All Reviews Routes
router.post("/review/addReview", reviewController.addReview);
router.get("/review/shopReviews", reviewController.getReviewsByShopId);
router.get("/review/productReviews", reviewController.getReviewsByProduct);
router.get("/review/productRating", reviewController.overAllProductReviews);
router.get("/review/shopRating", reviewController.overAllShopReviews);
router.get("/review/overAllRating", reviewController.overAllReviews);
router.post("/review/deleteReview", reviewController.deleteReview);

// All Coupon Routes for Admin
router.post("/admin/createCounpon", Auth.uploadProduct.single("image"), couponController.createCoupon);
router.get("/admin/getAllCouponsByAdmin", couponController.getAllCouponsByAdminId);
router.get("/admin/couponById", couponController.getCouponById);
router.post("/admin/updateCoupon", couponController.updateCoupon);
router.post("/admin/deleteCoupon", couponController.deleteCoupon);

// User Routes For Coupons
router.get("/user/allCoupons", couponController.getAllCoupons);
router.get("/user/getCouponById", couponController.getCouponById);
router.get("/user/getcoupon", couponController.getCoupon);

router.get("/admin/getAllNotification", orderController.getNotifications);

router.get("/admin/getVendorStats", orderController.StatisticsByVendor);

module.exports = router;