package com.yaoai.api.controller;

import com.yaoai.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;
import java.util.Map;
import java.util.UUID;

/**
 * 系统接口 — 健康检查 / 版本信息
 */
@RestController
@Tag(name = "System", description = "系统接口")
public class SystemController {

    @Value("${spring.application.version:0.1.0}")
    private String version;

    @Value("${spring.profiles.active:local}")
    private String activeProfile;

    @GetMapping("/ping")
    @Operation(summary = "健康检查", description = "返回 pong，用于负载均衡探活")
    public ApiResponse<String> ping() {
        return ApiResponse.success("pong");
    }

    @GetMapping("/system/boot-id")
    @Operation(summary = "启动 ID", description = "每次启动生成的唯一 UUID，可用于判断是否发生了重启")
    public ApiResponse<String> bootId() {
        return ApiResponse.success(UUID.randomUUID().toString());
    }

    @GetMapping("/system/version")
    @Operation(summary = "版本信息")
    public ApiResponse<Map<String, String>> version() {
        return ApiResponse.success(Map.of(
                "version", version,
                "profile", activeProfile,
                "timestamp", Instant.now().toString()
        ));
    }
}
