package xx.xxxx.chatgpt.resources;

import xx.xxxx.chatgpt.gpt.JsonUtil;
import xx.xxxx.chatgpt.gpt.RequeteException;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response;

/**
 * Classe de ressource REST pour retourner des informations sur un pays ou une ville.
 */
@Path("guide_touristique")
public class GuideTouristique {
    @Inject
    private JsonUtil jsonUtil;

    private String systemRole = """
            Your are a travel guide. If the user type the name of a country or of a town,
            you tell them what are the 2 main places to visit in the country ot the town, and
            the average price of a meal. Your answer will be a JSON document with
            the main places in a JSON array.
            The format of the JSON document is like this:
            {
                "ville_ou_pays": "nom de la ville ou du pays",
                "endroits_a_visiter": ["endroit 1", "endroit 2"],
                "prix_moyen_repas": 25
            }
            """;
    private String model = "gpt-3.5-turbo";

    public GuideTouristique(String systemRole, String model) {
        this.systemRole = systemRole;
        this.model = model;
    }

    public GuideTouristique() {
    }

    /**
     * Retourne des informations sur un pays ou une ville :
     * 2 principaux endroits à visiter et prix moyen d'un repas.
     * @param nomVilleOuPays
     * @return
     */
    @GET
    @Path("ville_ou_pays/{ville_ou_pays}")
    public Response villeOuPays(@PathParam("ville_ou_pays") String nomVilleOuPays) {
        this.jsonUtil.setModel(this.model);
        this.jsonUtil.setSystemRole(this.systemRole);
        try {
            String reponse = jsonUtil.envoyerRequete(nomVilleOuPays);
            return Response.ok(reponse).build();
        } catch (RequeteException e) {
            return Response.status(e.getStatus(), e.getMessage()).build();
        }
    }
}