package com.rj.config;

//import io.swagger.models.Info;

//import io.swagger.annotations.Info;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 *  http://localhost:9060/swagger-ui/index.html#/
 *  https://index.huayang-star.com/swagger-ui/index.html#/ai-card-bag-controller
 *
 * Author: 李中华  wx: spllzh  email(qq): 28668817@qq.com
 * Date: 2025/6/30 9:55
 **/
@Slf4j
@Configuration
public class SwaggerOpenAPI {

    @Value("${swagger.api.base-url}")
    private String baseUrl;


    @Configuration
    public class JacksonConfig {
        @Bean
        public ObjectMapper objectMapper() {
            return new ObjectMapper()
                    .registerModule(new JavaTimeModule())
                    .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        }
    }

    @Bean
    public OpenAPI customOpenAPI() {
        log.info("baseUrl = " + baseUrl);
        return new OpenAPI()
                .servers(List.of(new Server().url(baseUrl))) // 强制HTTPS
                .info(new Info()
                .title("AI Card API")
                .version("1.0.0")
                .description("Spring Boot 3.4 + Knife4j 集成 API")
                .contact(new Contact().name("Support").email("support@huayang-star.com"))
        );
    }
    @Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("public-api")
                .pathsToMatch("/api/**")
                .build();
    }

    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder()
                .group("admin-api")
                .pathsToMatch("/admin/**")
                .build();
    }




}

