const { Router } = require('express')
const router = Router()
/// //////////////////////////////////////////////////////// controllers
const { hasPermission } = require('../authentication')
const warrantyTermsController = require('../controllers/warrantyTermsController')
const contactPageController = require('../controllers/contactPageController')
const faqController = require('../controllers/faqController')
const learningController = require('../controllers/learningController')
const downloadCategoryController = require('../controllers/downloadCategoryController')
const downloadController = require('../controllers/downloadController')
const userController = require('../controllers/userController')
const ticketsController = require('../controllers/ticketsController')
const serialsExelController = require('../controllers/serialsExelController')
const helpController = require('../controllers/helpController')
const announcementController = require('../controllers/announcementController')
const lotteryPopUpController = require('../controllers/lotteryPopUpController')
const lotteryController = require('../controllers/lotteryController')
const representationController = require('../controllers/representationController')
const pieceController = require('../controllers/pieceController')
const pieceRequestController = require('../controllers/pieceRequestController')
const oldPieceRequestController = require('../controllers/oldPieceRequestController')
const bufferRequestController = require('../controllers/bufferRequestController')
const guaranteeReportController = require('../controllers/guaranteeReportController')
const transactionController = require('../controllers/transactionController')
const smsBroadcastController = require('../controllers/smsBroadcastController')
const surveyController = require('../controllers/surveyController')
const complaintController = require('../controllers/complaintController')
const brandController = require('../controllers/brandController')


/// //////////////////////////////////////////////////////// routes
/// ///////////// survey
router.get('/surveys',hasPermission('surveys'), surveyController.getAllForAdmin)
router.get('/surveys/:id',hasPermission('surveys'), surveyController.getOneForAdmin)

/// ///////////// Brand
router.post('/brand',hasPermission('brands'), brandController.createbrand)
router.get('/brand/:id',hasPermission('brands'), brandController.getbrand)
router.put('/brand/:id',hasPermission('brands'), brandController.updatebrand)
router.delete('/brand/:id',hasPermission('brands'), brandController.deletebrand)


/// ///////////// Complaint
router.get('/complaint',hasPermission('complaint'), complaintController.getsComplaint)
router.get('/complaint/:id',hasPermission('complaint'), complaintController.get)
router.put('/complaint/:id',hasPermission('apply'), complaintController.put)

/// ///////////// warranty terms
router.post('/warranty', hasPermission('warranty-terms'), warrantyTermsController.create)
router.put('/warranty/:id', hasPermission('warranty-terms'), warrantyTermsController.update)
router.delete('/warranty/:id', hasPermission('warranty-terms'), warrantyTermsController.delete)

/// ///////////// FAQ
router.post('/faq', hasPermission('faq'), faqController.create)
router.put('/faq/:id', hasPermission('faq'), faqController.update)
router.delete('/faq/:id', hasPermission('faq'), faqController.delete)

/// ///////////// Learning
router.post('/learning', hasPermission('learning'), learningController.create)
router.put('/learning/:id', hasPermission('learning'), learningController.update)
router.delete('/learning/:id', hasPermission('learning'), learningController.delete)

/// ///////////// download category
router.post('/dCategory', hasPermission('download-categories'), downloadCategoryController.create)
router.put('/dCategory/:id', hasPermission('download-categories'), downloadCategoryController.update)
router.delete('/dCategory/:id', hasPermission('download-categories'), downloadCategoryController.delete)

/// ///////////// downloads
router.post('/downloads', hasPermission('downloads'), downloadController.create)
router.put('/downloads/:id', hasPermission('downloads'), downloadController.update)
router.delete('/downloads/:id', hasPermission('downloads'), downloadController.delete)

// files
router.post('/downloads/file', hasPermission('downloads'), downloadController.addFile)
router.delete('/downloads/file/:id', hasPermission('downloads'), downloadController.deletFile)

/// ///////////// contact us
router.get('/contact', hasPermission('contact-us'), contactPageController.getAll)
router.get('/contact/:id', hasPermission('contact-us'), contactPageController.getOne)

/// ///////////// tickets
router.post('/addTicket', hasPermission('tickets'), ticketsController.add_ticket)
router.get('/tickets', hasPermission('tickets'), ticketsController.get_all_tickets_for_admin)
router.get('/ticket/:id', hasPermission('tickets'), ticketsController.get_one_ticket)
router.post('/addMessageToTicket/:id', hasPermission('tickets'), ticketsController.add_message_to_ticket)
router.get('/allUsers', hasPermission('tickets'), userController.get_all_users_for_admin)

/// ///////////// transactions
// router.get('/transactions', hasPermission('transactions'), userController.get_all_transactions_for_admin)
// router.get('/transaction/:id', hasPermission('transactions'), userController.get_one_transaction_for_admin)

/// ///////////// manage admins
router.post('/addAdmin', hasPermission('admins'), userController.register_admin)
router.put('/updateAdmin/:id', hasPermission('admins'), userController.update_admin)
router.delete('/deleteAdmin/:id', hasPermission('admins'), userController.delete_admin)
router.put('/updateAdminPassword', hasPermission('admins'), userController.update_user_password)
router.get('/admins', hasPermission('admins'), userController.get_admins)
router.get('/admin/:id', hasPermission('admins'), userController.get_one_admin)
router.get('/permissions', hasPermission('admins'), userController.permissions)

/// ///////////// manage users
router.get('/users', hasPermission('customers'), userController.get_all_users_for_admin)
router.get('/user/:id', hasPermission('customers'), userController.get_one_user_for_admin)
router.put('/user/:id', hasPermission('customers'), userController.updateUserByAdmin)
router.put('/user/changeVerityInfo/:id', hasPermission('customers'), userController.change_verity_info_by_admin)
router.put('/user/changePanatechInfo/:id', hasPermission('customers'), userController.change_panatech_info_by_admin)
router.put('/user/update/:id', hasPermission('customers'), userController.update_user_by_admin)


/// ///////////// serials exel file
router.post('/addExel', hasPermission('serials-exel'), serialsExelController.addExel)
router.delete('/removeExel/:name', hasPermission('serials-exel'), serialsExelController.removeExel)
router.get('/serialExels', hasPermission('serials-exel'), serialsExelController.getAllExels)

/// ///////////// update help page
router.put('/help', hasPermission('help'), helpController.set)

/// ///////////// announcements
router.post('/announcements', hasPermission('announcements'), announcementController.create)
router.get('/announcements', hasPermission('announcements'), announcementController.getAllForAdmin)
router.get('/announcementsUsers', hasPermission('announcements'), userController.get_all_users_for_admin)
router.get('/announcements/:id', hasPermission('announcements'), announcementController.getOneForAdmin)
router.delete('/announcements/:id', hasPermission('announcements'), announcementController.deleteAnnouncement)
// router.put('/announcement/:id', hasPermission('announcements'), announcementController.updateByAdmin)

/// ///////////// lottery
router.put('/lotteryPopUp', hasPermission('lotteryPopUp'), lotteryPopUpController.modify)
router.post('/lottery', hasPermission('lottery'), lotteryController.addLottery)
router.delete('/lottery/:lotteryId', hasPermission('lottery'), lotteryController.deleteLottery)
router.put('/lottery/:lotteryId', hasPermission('lottery'), lotteryController.updateLottery)
router.get('/lottery/:lotteryId', hasPermission('lottery'), lotteryController.getOneLottery)
router.get('/lotteries', hasPermission('lottery'), lotteryController.getAllLotteries)

/// ///////////// representations (agents)
router.get('/representations', hasPermission('representations'), representationController.getAll)
router.get('/representation/:id', hasPermission('representations'), representationController.getOne)
router.put('/representationStatus/:id', hasPermission('representations'), representationController.change_form_status)
router.post('/addAgentByAdmin', hasPermission('representations'), representationController.add_agent_by_admin)

/// ///////////// pieces
router.post('/piece', hasPermission('pieces'), pieceController.add_piece)
router.put('/piece/:id', hasPermission('pieces'), pieceController.update_piece)
router.delete('/piece/:id', hasPermission('pieces'), pieceController.remove_piece)
router.get('/pieces', hasPermission('pieces'), pieceController.get_all_pieces)
router.get('/pieces/:id', hasPermission('pieces'), pieceController.get_one_pieces)

/// ///////////// piece requests
router.get('/prList', hasPermission('piece-requests'), pieceRequestController.get_all_pr_for_admin)
router.get('/pr/:id', hasPermission('piece-requests'), pieceRequestController.get_one_pr_for_admin)
router.put('/prStatus/:id', hasPermission('piece-requests'), pieceRequestController.change_pr_status_by_admin)

/// ///////////// oldPiece requests
router.get('/oprList', hasPermission('op-requests'), oldPieceRequestController.get_all_opr_for_admin)
router.get('/opr/:id', hasPermission('op-requests'), oldPieceRequestController.get_one_opr_for_admin)
router.put('/oprStatus/:id', hasPermission('op-requests'), oldPieceRequestController.change_opr_status_by_admin)

/// ///////////// buffer requests
router.get('/brList', hasPermission('buffer-requests'), bufferRequestController.get_all_br_for_admin)
router.get('/br/:id', hasPermission('buffer-requests'), bufferRequestController.get_one_br_for_admin)
router.put('/brStatus/:id', hasPermission('buffer-requests'), bufferRequestController.change_br_status_by_admin)

/// ///////////// agents guarantee jobs reports
router.get('/grList', hasPermission('guarantee-reports'), guaranteeReportController.get_all_gr_for_admin)
router.get('/gr/:id', hasPermission('guarantee-reports'), guaranteeReportController.get_one_gr_for_admin)
// router.put('/grStatus/:id', hasPermission('guarantee-reports'), guaranteeReportController.change_gr_status_by_admin)

/// ///////////// agent inbox
router.get('/allAgentsInbox', hasPermission('agentsInbox'), transactionController.get_all_agents_inbox_for_admin)
router.get('/allAgentsInbox/:id', hasPermission('agentsInbox'), transactionController.get_one_transaction_for_admin)

/// ///////////// one agent details and reports
router.get('/agentDetails/:id', hasPermission('agents'), representationController.getOne)
router.get('/agentInbox/:agent_id', hasPermission('agents'), transactionController.get_one_agent_inbox_for_admin)
router.get('/agentBr/:agent_id', hasPermission('agents'), bufferRequestController.get_oneAgent_br_for_admin)
router.get('/agentOpr/:agent_id', hasPermission('agents'), oldPieceRequestController.get_oneAgent_opr_for_admin)
router.get('/agentPr/:agent_id', hasPermission('agents'), pieceRequestController.get_oneAgent_pr_for_admin)

/// ///////////// update agent info
router.put('/updateAgent/:id', hasPermission('agentUpdate'), representationController.update_representation_by_admin)
router.post('/revokeAgent/:id', hasPermission('agentUpdate'), representationController.revoke_representation_by_admin)
router.get('/revokedAgents', representationController.get_revoked_agents_for_admin)

// update files
router.post(
  '/representationImages/:userType/:representation_code',
  representationController.upload_image_to_representation
)
router.delete(
  '/representationImages/:userType/:representation_code/:imgId',
  representationController.remove_image_from_representation
)

/// ///////////// all agents report (advance report)
router.get('/report/pieces', hasPermission('agentReports'), pieceController.get_all_pieces)
router.get(
  '/report/allAgentsInbox',
  hasPermission('agentReports'),
  transactionController.get_all_agents_inbox_for_admin
)
router.get('/report/grList', hasPermission('agentReports'), guaranteeReportController.get_all_gr_for_admin)
router.get('/report/brList', hasPermission('agentReports'), bufferRequestController.get_all_br_for_admin)
router.get('/report/prList', hasPermission('agentReports'), pieceRequestController.get_all_pr_for_admin)
router.get('/report/oprList', hasPermission('agentReports'), oldPieceRequestController.get_all_opr_for_admin)

/// ///////////// broadcast sms for users
router.post('/broadcastSMS', hasPermission('sms'), smsBroadcastController.broadcast)
router.get('/smsBroadcasts', hasPermission('sms'), smsBroadcastController.getAllForAdmin)
router.get('/smsBroadcasts/:id', hasPermission('sms'), smsBroadcastController.getOneForAdmin)
router.get('/usersForSMS', hasPermission('sms'), userController.get_all_users_for_admin)




module.exports = router
