package cn.qinys.platform.mobile.tool;

import cn.qinys.platform.base.utils.SpringUtil;
import cn.qinys.platform.entity.wishing.WishingTreeExtension;
import cn.qinys.platform.mobile.mapper.WishingTreeExtensionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.web.client.RestTemplate;

/**
 * @author lie tan
 * @description
 * @date 2026-06-13 10:47
 **/
@Slf4j
public class WeatherTools {

    String key = "88a0c82c3f60a748c6c638ef9db16bca";
    String url = "https://restapi.amap.com/v3/weather/weatherInfo?city={0}&key={1}";

    private Integer treeId;

    public WeatherTools() {
    }

    public WeatherTools(Integer treeId) {
        this.treeId = treeId;
    }


    @Tool(description = """
            get the weather forecast for the special wishing tree
            along with the current date and time in the user's timezone
            """)
    public String getWeather() {
        log.info("调用天气工具了");
        WishingTreeExtensionMapper extensionMapper = SpringUtil.getBean(WishingTreeExtensionMapper.class);
        WishingTreeExtension extension = extensionMapper.selectByTreeId(treeId);
        if (extension == null || extension.getAdcode() == null) {
            return null;
        }
        RestTemplate restTemplate = SpringUtil.getBean(RestTemplate.class);
        return restTemplate.getForObject(url, String.class, extension.getAdcode(), key);
    }


}
