package sklep.rest;

import java.util.List;

import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import sklep.model.Product;

// Tak wygląda klasa wygenerowana przez polecenie "New JAX-RS Resource" w Eclipse z dodatkiem wtyczki JBossTolls (JAX-RS Tools)
// Komentuję adnotacje przed klasą, aby nie wpływało to na działanie aplikacji.

// @RequestScoped
// @Path("/products")
// @Produces({ "application/xml", "application/json" })
// @Consumes({ "application/xml", "application/json" })
public class ProductEndpoint {

	@POST
	public Response create(final Product product) {
		//TODO: process the given product 
		//you may want to use the following return statement, assuming that Product#getId() or a similar method 
		//would provide the identifier to retrieve the created Product resource:
		//return Response.created(UriBuilder.fromResource(ProductEndpoint.class).path(String.valueOf(product.getId())).build()).build();
		return Response.created(null).build();
	}

	@GET
	@Path("/{id:[0-9][0-9]*}")
	public Response findById(@PathParam("id") final Long id) {
		//TODO: retrieve the product 
		Product product = null;
		if (product == null) {
			return Response.status(Status.NOT_FOUND).build();
		}
		return Response.ok(product).build();
	}

	@GET
	public List<Product> listAll(@QueryParam("start") final Integer startPosition,
			@QueryParam("max") final Integer maxResult) {
		//TODO: retrieve the products 
		final List<Product> products = null;
		return products;
	}

	@PUT
	@Path("/{id:[0-9][0-9]*}")
	public Response update(@PathParam("id") Long id, final Product product) {
		//TODO: process the given product 
		return Response.noContent().build();
	}

	@DELETE
	@Path("/{id:[0-9][0-9]*}")
	public Response deleteById(@PathParam("id") final Long id) {
		//TODO: process the product matching by the given id 
		return Response.noContent().build();
	}

}
