package marketing.heyday.hartmann.fotodocumentation.rest;

import static marketing.heyday.hartmann.fotodocumentation.rest.jackson.ApplicationConfigApi.JSON_OUT;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.resteasy.annotations.GZIP;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.ejb.EJB;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
import marketing.heyday.hartmann.fotodocumentation.core.service.CustomerPictureService;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerListValue;
import marketing.heyday.hartmann.fotodocumentation.rest.vo.CustomerValue;

/**
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 21 Jan 2026
 */
@RequestScoped
@Path("customer")
public class CustomerResource {
	private static final Log LOG = LogFactory.getLog(CustomerResource.class);
		
	@EJB
	private CustomerPictureService customerPictureService;
	
	@GZIP
	@GET
	@Path("")
	@Produces(JSON_OUT)
	@Operation(summary = "Get customer list")
	@ApiResponse(responseCode = "200", description = "Successfully retrieved customer list", content = @Content(mediaType = JSON_OUT, array = @ArraySchema(schema = @Schema(implementation = CustomerListValue.class))))
	public Response doGetCustomerList(@QueryParam("query") String query, @QueryParam("startsWith") String startsWith) {
		LOG.debug("Query customers for query " + query + " startsWith: " + startsWith);
		var retVal =  customerPictureService.getAll(query, startsWith);
		return Response.ok().entity(retVal).build();
	}
	
	@GZIP
	@GET
	@Path("{id}")
	@Produces(JSON_OUT)
	@Operation(summary = "Get customer value")
	@ApiResponse(responseCode = "200", description = "Successfully retrieved customer value", content = @Content(mediaType = JSON_OUT, array = @ArraySchema(schema = @Schema(implementation = CustomerValue.class))))
	public Response doGetDetailCustomer(@PathParam("id") Long id) {
		LOG.debug("Get Customer details for id " + id);
		var retVal =  customerPictureService.get(id);
		return Response.ok().entity(retVal).build();
	}
}
