const saveCards = require("../middleware/genCards");

class GeneratorCardsController {
    async getScreen(req, res) {
        const { lat, lng, type, wayId, zoom, id, address, number  } = req.query;

        if (req.possibilities.can_add_territory) {
            let result = await saveCards({ center: {lat:lat,lng:lng}, wayId: wayId, zoom: zoom ?? 18, type: type, number: id, address: `${address} ${number}` });

            console.log(result);
            

            if (result) {
                return res.status(200).send(result);
            } else {
                return res
                    .status(404)
                    .send({ message: 'Image creation error.' });
            }
        } else {
            return res
                .status(403)
                .send({ message: 'The user does not have enough rights.' });
        }

    }
}

module.exports = new GeneratorCardsController();