package marketing.heyday.hartmann.fotodocumentation.rest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.ejb.EJB;
import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder;
import jakarta.ws.rs.core.Response.Status;
import marketing.heyday.hartmann.fotodocumentation.core.service.PictureService;
import marketing.heyday.hartmann.fotodocumentation.core.utils.StorageUtils.StorageState;

/**
 * 
 * <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("picture")
public class PictureResource {
	private static final Log LOG = LogFactory.getLog(PictureResource.class);
		
	@EJB
	private PictureService pictureService;
	
	@DELETE
	@Path("{id}")
	@Operation(summary = "Delete picture from database")
	@ApiResponse(responseCode = "200", description = "Task successfully deleted")
	@ApiResponse(responseCode = "404", description = "Task not found")
	@ApiResponse(responseCode = "403", description = "Insufficient permissions")
	public Response doDelete(@PathParam("id") Long id) {
		LOG.debug("Delete picture with id " + id);
		var state = pictureService.delete(id);
		return deleteResponse(state).build();
	}
	
	protected ResponseBuilder deleteResponse(StorageState state) {
		return switch(state) {
		case OK -> Response.status(Status.OK);
		case NOT_FOUND -> Response.status(Status.NOT_FOUND);
		default -> Response.status(Status.INTERNAL_SERVER_ERROR);
		};
	}
}
