const express = require('express');
const router = express.Router();
const { PetGroup, PetSpecies, PetBreed, PetDisease } = require('../models');

// GET /common/initial-data
// Returns hierarchical master data for frontend caching
router.get('/initial-data', async (req, res) => {
  try {
    const groups = await PetGroup.findAll({
      include: [
        {
          model: PetSpecies,
          include: [{ model: PetBreed }]
        }
      ]
    });

    const diseases = await PetDisease.findAll();

    res.json({
      groups,
      diseases,
    });
  } catch (error) {
    console.error('Error fetching initial data:', error);
    res.status(500).json({ message: 'Server Error' });
  }
});

module.exports = router;
