// Path: src/main/java/uk/gov/homeoffice/emailapi/entities/EmailApiStatus.java
// public enum EmailApiStatus implements StatusType {
//     InvalidEmail(422, "Invalid recipient email"),
//     TemplateUnreadable(422, "Template does not exist"),
//     TemplateInvalid(422, "Template Invalid"),
//     SendingEmailFailed(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
//         "Failed sending email to SMTP server.");
// 
//     private final Status.Family family;
// 
//     private final String reason;
// 
//     private final int code;
// 
//     EmailApiStatus(final int statusCode, final String reasonPhrase) {
//         this.code = statusCode;
//         this.reason = reasonPhrase;
//         this.family = Status.Family.familyOf(statusCode);
//     }
// 
//     @JsonValue
//     public Map<String, List<String>> toEntity() {
// 
//         final Map<String, List<String>> map = new HashMap<>();
//         List<String> errors = new ArrayList<>();
//         errors.add(reason);
//         map.put("errors", errors);
// 
//         return map;
//     }
// 
//     @Override
//     public int getStatusCode() {
//         return code;
//     }
// 
//     @Override
//     public Status.Family getFamily() {
//         return family;
//     }
// 
//     @Override
//     public String getReasonPhrase() {
//         return reason;
//     }
// }
// 
// Path: src/main/java/uk/gov/homeoffice/emailapi/templatedemailfactory/templating/TemplatePopulatorParsingException.java
// public class TemplatePopulatorParsingException extends Exception {
//     public TemplatePopulatorParsingException(Throwable cause) {
//         super(cause);
//     }
// 
//     public TemplatePopulatorParsingException(String message) {
//         super(message);
//     }
// }


import org.slf4j.LoggerFactory;
import uk.gov.homeoffice.emailapi.entities.EmailApiStatus;
import uk.gov.homeoffice.emailapi.templatedemailfactory.templating.TemplatePopulatorParsingException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
package uk.gov.homeoffice.emailapi.resources;



@Provider
public class TemplatePopulatorParsingExceptionMapper
    implements ExceptionMapper<TemplatePopulatorParsingException> {


    private static final org.slf4j.Logger LOGGER =
        LoggerFactory.getLogger(TemplatePopulatorParsingExceptionMapper.class);

    @Override
    public Response toResponse(TemplatePopulatorParsingException exception) {
        LOGGER.error("Template is broken", exception);

        return Response.status(EmailApiStatus.TemplateInvalid).encoding(MediaType.APPLICATION_JSON)
// Path: src/main/java/uk/gov/homeoffice/emailapi/entities/EmailApiStatus.java
// public enum EmailApiStatus implements StatusType {
//     InvalidEmail(422, "Invalid recipient email"),
//     TemplateUnreadable(422, "Template does not exist"),
//     TemplateInvalid(422, "Template Invalid"),
//     SendingEmailFailed(Status.INTERNAL_SERVER_ERROR.getStatusCode(),
//         "Failed sending email to SMTP server.");
// 
//     private final Status.Family family;
// 
//     private final String reason;
// 
//     private final int code;
// 
//     EmailApiStatus(final int statusCode, final String reasonPhrase) {
//         this.code = statusCode;
//         this.reason = reasonPhrase;
//         this.family = Status.Family.familyOf(statusCode);
//     }
// 
//     @JsonValue
//     public Map<String, List<String>> toEntity() {
// 
//         final Map<String, List<String>> map = new HashMap<>();
//         List<String> errors = new ArrayList<>();
//         errors.add(reason);
//         map.put("errors", errors);
// 
//         return map;
//     }
// 
//     @Override
//     public int getStatusCode() {
//         return code;
//     }
// 
//     @Override
//     public Status.Family getFamily() {
//         return family;
//     }
// 
//     @Override
//     public String getReasonPhrase() {
//         return reason;
//     }
// }
// 
// Path: src/main/java/uk/gov/homeoffice/emailapi/templatedemailfactory/templating/TemplatePopulatorParsingException.java
// public class TemplatePopulatorParsingException extends Exception {
//     public TemplatePopulatorParsingException(Throwable cause) {
//         super(cause);
//     }
// 
//     public TemplatePopulatorParsingException(String message) {
//         super(message);
//     }
// }


// Path: src/main/java/uk/gov/homeoffice/emailapi/resources/TemplatePopulatorParsingExceptionMapper.java
import org.slf4j.LoggerFactory;
import uk.gov.homeoffice.emailapi.entities.EmailApiStatus;
import uk.gov.homeoffice.emailapi.templatedemailfactory.templating.TemplatePopulatorParsingException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

package uk.gov.homeoffice.emailapi.resources;



@Provider
public class TemplatePopulatorParsingExceptionMapper
    implements ExceptionMapper<TemplatePopulatorParsingException> {


    private static final org.slf4j.Logger LOGGER =
        LoggerFactory.getLogger(TemplatePopulatorParsingExceptionMapper.class);

    @Override
    public Response toResponse(TemplatePopulatorParsingException exception) {
        LOGGER.error("Template is broken", exception);

        return Response.status(EmailApiStatus.TemplateInvalid).encoding(MediaType.APPLICATION_JSON)
            .entity(EmailApiStatus.TemplateInvalid).build();