package in.cdac.medinfo.csnotk.csnoserv.rest;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import in.cdac.medinfo.csnotk.csnoserv.corsfilter.CORSFilter;
public class CORSHeaderSupport{

    static CORSFilter CORSFilter = new CORSFilter();


    /**
     * Add HTTP Header For every API call to CSNOSERV
     * @param jakarta.ws.rs.core.Response.Status {@link Status} HTTP Status Code
     * @param entity {@link String}  JSON String
     * @return jakarta.ws.rs.core.Response Entity in JSON format
     */


    protected static Response addCORSHeader(Status status, String entity) {
        //adding required HTTP Header To The Response
        return Response.status(status).entity(entity)
                .header("Access-Control-Allow-Method", CORSFilter.getAccessControlAllowMethods())
                .header("Access-Control-Allow-Credentials", CORSFilter.getAccessControlAllowCredentials()) //add true in angular
                .header("Access-Control-Allow-Headers",CORSFilter.getAccessControlAllowHeaders())
                .header("Access-Control-Request-Headers",CORSFilter.getAccessControlRequestHeaders())
                .build();
    }


}