package com.pandoli365.bibimbap.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Path;
import java.nio.file.Paths;

@Configuration
public class UploadResourceConfig implements WebMvcConfigurer {

    @Value("${app.upload.game-storage-path:src/main/resources/static}")
    private String gameStoragePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        Path uploadPath = Paths.get(gameStoragePath).toAbsolutePath().normalize();
        String profileLocation = uploadPath.resolve("profile").toUri().toString();

        registry.addResourceHandler("/profile/**")
                .addResourceLocations(profileLocation);
    }
}
