import express from 'express';
import {
  submitSurvey,
  getProjectSurveys,
  getSurveyStatistics,
  getSurveyById,
  updateSurvey,
  permanentDeleteSurvey,
  getDashboardCards,
  getAdditionalDashboardCards,
  getConditionChart,
  getRemarksChart,
  getOwnershipChart,
  getSpeciesChart,
  getEconomicImportanceChart,
  getQCPendingSurveys,
  getQCSurveyById,
  getSpeciesList,
  getWardsList,
  getProjectUsers,
  getTreeList,
  submitQCReview,
  getSurveyInventory,
  getCardDetails,
  softDeleteSurvey,
  getTreeDataById,
  addQcLogs,
  getQcLogs
} from '../controllers/surveyController.js';
import { requireAuth } from '../middleware/auth.js';

const router = express.Router();

// Mobile API routes (no authentication required for survey submission)
router.post('/submit', submitSurvey);

// Protected routes (require authentication)
router.get('/project/:treelogy_id', requireAuth, getProjectSurveys);
router.get('/project/:treelogy_id/statistics', requireAuth, getSurveyStatistics);
router.get('/project/:treelogy_id/survey/:survey_id', requireAuth, getSurveyById);
router.put('/project/:treelogy_id/survey/:survey_id', requireAuth, updateSurvey);
router.delete('/project/:treelogy_id/survey/:survey_id/softDelete', requireAuth, softDeleteSurvey);
router.delete('/project/:treelogy_id/survey/:survey_id', requireAuth, permanentDeleteSurvey);

// Dashboard routes - temporarily removing auth for testing
router.get('/project/:treelogy_id/dashboard/cards', getDashboardCards);
router.get('/project/:treelogy_id/dashboard/cards/additional', getAdditionalDashboardCards);
router.get('/project/:treelogy_id/dashboard/charts/condition', getConditionChart);
router.get('/project/:treelogy_id/dashboard/charts/remarks', getRemarksChart);
router.get('/project/:treelogy_id/dashboard/charts/ownership', getOwnershipChart);
router.get('/project/:treelogy_id/dashboard/charts/species', getSpeciesChart);
router.get('/project/:treelogy_id/dashboard/charts/economic-importance', getEconomicImportanceChart);

// QC routes
router.get('/project/:treelogy_id/qc/pending', getQCPendingSurveys);
router.get('/project/:treelogy_id/qc/survey/:survey_id', getQCSurveyById);
router.get('/project/:treelogy_id/species', getSpeciesList);
router.get('/project/:treelogy_id/wards', getWardsList);
router.get('/project/:treelogy_id/users', getProjectUsers);
router.get('/project/:treelogy_id/trees', getTreeList);
router.post('/project/:treelogy_id/qc/log', addQcLogs);
router.get('/project/:treelogy_id/qc/log', getQcLogs);
router.post('/project/:treelogy_id/qc/:survey_id', submitQCReview);

// Survey Inventory routes
router.get('/project/:treelogy_id/inventory', getSurveyInventory);

// Dashboard Card Details routes
router.get('/project/:treelogy_id/dashboard/card-details/:card_id', getCardDetails);

router.get('/get-survey-by-id',getTreeDataById)

export default router;
