const express = require('express')
const blockCheck = require('../../../middlewares/blockCheck')
const { createAdvertisingValidationRules, createAdvertising, getAdvertisingTypes, getAdvertisingCategory, getSingleAdvertising, getAdvertisingFeatures, getAdvertisings, toggleLike, addComment, getComments, rateAdvertising, getUserAdvertisings, editAdvertising, getUserSingleAdvertising, getUserAdvertisingProfile, updateUserAdvertisingProfile, getAdvertisingsWeb, getSingleAdvertisingWeb, getUserAdvertisingProfileWeb } = require('../../../controllers/application/advertising/advertisingController')
const auth = require('../../../middlewares/auth')
const { initiateAdvertisingPayment, handleAdvertisingPaymentCallback, handleAdvertisingRepublishPaymentCallback, republishAdvertisingPayment, handleSuccessfulAdvertisingPayment, handleFailedAdvertisingPayment, handleFailedAdvertisingRepublishPayment, handleSuccessfulAdvertisingRepublishPayment } = require('../../../controllers/application/payment/paymentController')
const { initiateAdvertisingPaymentWeb, handleAdvertisingPaymentCallbackWeb, republishAdvertisingPaymentWeb, handleAdvertisingRepublishPaymentCallbackWeb } = require('../../../controllers/application/payment/paymentControllerWeb')
const router = express.Router()
router.get('/', [auth], getAdvertisings)
router.get('/web', getAdvertisingsWeb)
router.get('/profile', [auth], getUserAdvertisingProfile)
router.get('/profile-web', getUserAdvertisingProfileWeb)
router.patch('/profile', [auth], [blockCheck], updateUserAdvertisingProfile)
router.get('/user-advertising', [auth], getUserAdvertisings)
router.post('/create', [auth], [blockCheck], createAdvertisingValidationRules(), createAdvertising)
router.get('/types', [auth], getAdvertisingTypes)
router.get('/categories', getAdvertisingCategory)
router.get('/features', [auth], getAdvertisingFeatures)
router.get('/get/:advertisingId', [auth], getSingleAdvertising)
router.get('/get/web/:advertisingId', getSingleAdvertisingWeb)
router.get('/get-detail/:advertisingId', [auth], getUserSingleAdvertising)
router.post('/initiate-payment', [auth], [blockCheck], initiateAdvertisingPayment)
router.post('/initiate-payment-web', [auth], [blockCheck], initiateAdvertisingPaymentWeb)
router.post('/republish-payment', [auth], [blockCheck], republishAdvertisingPayment)
router.post('/republish-payment-web', [auth], [blockCheck], republishAdvertisingPaymentWeb)
router.get('/payment', handleAdvertisingPaymentCallback)
router.get('/payment-web', handleAdvertisingPaymentCallbackWeb)
router.get('/republish-verify-payment', handleAdvertisingRepublishPaymentCallback)
router.get('/republish-verify-payment-web', handleAdvertisingRepublishPaymentCallbackWeb)
router.post('/like', [blockCheck], [auth], toggleLike)
router.post('/comment', [blockCheck], [auth], addComment)
router.get('/comments', getComments)
router.post('/rate', [blockCheck], [auth], rateAdvertising)
router.post('/edit/:id', [blockCheck], [auth], editAdvertising)

// Route for handling successful payment
router.post('/payment-success', handleSuccessfulAdvertisingPayment)
// Route for handling failed payment
router.post('/payment-failed', handleFailedAdvertisingPayment)
// Route for handling successful payment
router.post('/republish-payment-success', handleSuccessfulAdvertisingRepublishPayment)
// Route for handling failed payment
router.post('/republish-payment-failed', handleFailedAdvertisingRepublishPayment)

module.exports = router
module.exports = router
