package org.example.tampoposerverdtram.resources;
import java.util.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.client.*;
import jakarta.ws.rs.core.*;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
@Path("/deletedFriendPair")
@Component
public class DeletedFriendPair {
private Map<String, Object> value = new HashMap<>();
private Client client = ClientBuilder.newClient();
@Produces(MediaType.APPLICATION_JSON)
@GET
public Map<String, Object> getValue() {
return new HashMap<>(this.value);
}
@PUT
public void deleteFriend(@FormParam("id") String id) throws JsonProcessingException {
String user0Id = client.target("http://localhost:8080").path("/friends/pairs/" + id + "/user0Id").request().get(String.class);
String user1Id = client.target("http://localhost:8080").path("/friends/pairs/" + id + "/user1Id").request().get(String.class);
Map<String, Object> temp_json0 = new HashMap<>();
temp_json0.put("pairId", id);
temp_json0.put("user0Id", user0Id);
temp_json0.put("user1Id", user1Id);
this.value = temp_json0;
Form form = new Form();
form.param("deletedFriendPair", this.value.toString());
Entity<Form> entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
String result = client.target("http://localhost:8080").path("/users/"+user0Id+"/friends").request().post(entity, String.class);
form = new Form();
form.param("deletedFriendPair", this.value.toString());
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
result = client.target("http://localhost:8080").path("/users/"+user1Id+"/friends").request().post(entity, String.class);
form = new Form();
form.param("deletedFriendPair", this.value.toString());
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);
result = client.target("http://localhost:8080").path("/friends/users").request().post(entity, String.class);
result = client.target("http://localhost:8080").path("/friends/pairs").queryParam("deletedFriendPair", this.value.toString()).request().delete(String.class);
}
}