package kr.lunaticbum.back.lun.configs

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.CacheControl
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import java.time.Duration


@Configuration
class AppConfig : WebMvcConfigurer {
    @Value("\${resource.handler}")
    private val resourceHandler: String? = null

    @Value("\${resource.location}")
    private val resourceLocation: String? = null

    val cacheControl: CacheControl = CacheControl.maxAge(Duration.ofHours(1))

    @Bean
    fun authInterceptor(): BumsInterceptor {
        return BumsInterceptor()
    }
    override fun addResourceHandlers(registry: org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry) {

        registry.addResourceHandler(resourceHandler).addResourceLocations(resourceLocation).setCacheControl(cacheControl)
    }

    @Bean
    fun passwordEncoder(): PasswordEncoder = BCryptPasswordEncoder()

    override fun addInterceptors(registry: InterceptorRegistry) {
        registry.addInterceptor(authInterceptor())
            .addPathPatterns(
                "/home.bs",
                "/bums/where.bs" ,
                "/tlg/repotToMe.bjx",
                "/user/login.bs", "/user/signup.bs","/user/login.bjx",
                "/blog/viewer/**" , "/blog/posts" , "/blog/rankOfViews.bjx","/blog/recentOfPost.bjx"
            )
//        super.addInterceptors(registry)
    }


//    @Bean
//    fun qdrantClient(): QdrantClient {
//        return QdrantClient("https://ollama.lunaticbum.kr:6334")
//    }

//    @Bean
//    fun chatClient(): OllamaApi {
//        return OllamaApi("https://lama.lunaticbum.kr")
//
////            .withDefaultOptions(
////                OllamaOptions.create()
////                    .withModel("phi4:14b")
////                    .withNumThread(5)
////                    .withSeed(5)
////                    .withTemperature(0.9f))
//    }
//    @Bean
//    fun getProperty()  : Map<String,String>{
//        println("telegramBotKey >>>> $telegramBotKey")
//        println("telegramMyId >>>> $telegramMyId")
//        println("weatherApiKey >>>> $weatherApiKey")
//
//        return hashMapOf(Pair("telegramMyId",telegramMyId))
//    }
//    @Bean
//    fun memberRepository(): MemberRepository {
//        return MemoryMemberRepository()
//    }
//
//    @Bean
//    fun discountPolicy(): DiscountPolicy {
//        return RateDiscountPolicy()
//    }
//
//    @Bean
//    fun memberService(): MemberService {
//        return MemberServiceImpl(memberRepository())
//    }
//
//    @Bean
//    fun orderService(): OrderService {
//        return OrderServiceImpl(memberRepository(), discountPolicy())
//    }

}