package com.aluracursos.screenmatch.principal;
import com.aluracursos.screenmatch.modelos.Titulo;
import com.aluracursos.screenmatch.modelos.TituloOmdb;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
public class principalRecuest {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner scanner = new Scanner(System.in);
System.out.println("Introduzca el nombre de la pelicula: ");
var busqueda = scanner.nextLine();
String direccion= "http://www.omdbapi.com/?t="+busqueda+"&apikey=7959d625";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(direccion))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
//System.out.println(response.body());
String json= response.body();
System.out.println(json);
//Gson gson = new Gson();
//Titulo mtitulo = gson.fromJson(json,Titulo.class);
//System.out.println("mi titulo :"+ mtitulo.getNombre());
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
TituloOmdb mtituloOmdb = gson.fromJson(json,TituloOmdb.class);
System.out.println(mtituloOmdb);
Titulo mtitulo = new Titulo(mtituloOmdb);
System.out.println(mtitulo);
}
}