package app.mealsmadeeasy.api.image;

import app.mealsmadeeasy.api.security.EndpointAuthConfigurator;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;
import org.springframework.stereotype.Component;

@Component
public class ImageEndpointAuthConfigurator implements EndpointAuthConfigurator {

    @Override
    public void configure(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
        registry.requestMatchers(HttpMethod.GET, "/images/**").permitAll();
        registry.requestMatchers(HttpMethod.GET, "/images/*/*/exists").authenticated();
        registry.requestMatchers(HttpMethod.POST, "/images/**").authenticated();
        registry.requestMatchers(HttpMethod.PUT, "/images/**").authenticated();
        registry.requestMatchers(HttpMethod.DELETE, "/images/**").authenticated();
    }

}
