package marketing.heyday.hartmann.fotodocumentation.core.service;

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

import jakarta.annotation.security.PermitAll;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.persistence.EntityNotFoundException;
import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
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: 19 Jan 2026
 */
@Stateless
@LocalBean
@PermitAll
public class PictureService extends AbstractService {
	private static final Log LOG = LogFactory.getLog(PictureService.class);

	public StorageState delete(Long id) {
		return super.delete(Picture.class, id);
	}

	public StorageState updateEvaluationStatus(Long id, Integer value) {
		try {
			Picture entity = entityManager.getReference(Picture.class, id);
			entity.setEvaluation(value);
			entityManager.flush();
			return StorageState.OK;
		} catch (EntityNotFoundException e) {
			LOG.warn("Failed to update evaluation value not found " + id, e);
			ejbContext.setRollbackOnly();
			return StorageState.NOT_FOUND;
		}
	}
}
