package com.nokia.dingtalk_auto.config;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nokia.common.dingtalk.DingTalkUtil;

/**
 * 注入钉钉机器人工具类
 */
@Configuration
public class DingTalkUtilConfig {

    @Resource
    private RestTemplate restTemplate;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private ObjectMapper objectMapper;

    @Value("${remind.dingTalk.appKey:dingothmdq6opv6hjrm5}")
    private String remindAppKey;

    @Value("${remind.dingTalk.appSecret:SeoyAwUnzFIFY4j4CX089HJ0i-pj1BIzByB3AZcnbCQaq94lZvazFpfEGGQwPznc}")
    private String remindAppSecret;

    @Value("${remind.dingTalk.openConversationId:cidcWmmFwduUTDB3G0vPNOldQ==}")
    private String remindOpenConversationId;

    @Value("${tslTask.dingTalk.appKey}")
    private String tslAppKey;

    @Value("${tslTask.dingTalk.appSecret}")
    private String tslAppSecret;

    @Value("${tslTask.dingTalk.openConversationId}")
    private String tslOpenConversationId;

    @Bean("remindDingTalkUtil")
    public DingTalkUtil remindDingTalkUtil() {
        DingTalkUtil dingTalkUtil = new DingTalkUtil(remindAppKey, remindAppSecret, restTemplate, redisTemplate,
                objectMapper);
        dingTalkUtil.setConversationId(remindOpenConversationId);
        return dingTalkUtil;
    }

    @Bean("tslTaskDingTalkUtil")
    public DingTalkUtil tslTaskDingTalkUtil() {
        DingTalkUtil dingTalkUtil = new DingTalkUtil(tslAppKey, tslAppSecret, restTemplate, redisTemplate,
                objectMapper);
        dingTalkUtil.setConversationId(tslOpenConversationId);
        return dingTalkUtil;
    }
}
