package thyyxxk.webserver.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import thyyxxk.webserver.config.envionment.ApiUrl;

/**
 * @author dj
 */
@Service("TokenService")
@RequiredArgsConstructor
public class TokenService {
    private final RestTemplate template;
    private final ApiUrl apiUrl;


    public String getWeComAddressBookToken() {
        String url = apiUrl.getScheduledApi() + "/accessToken/get?key=corpwxBookAddressToken";
        return template.getForObject(url, String.class);
    }

    public String getWeComSendMsgToken() {
        String url = apiUrl.getScheduledApi() + "/accessToken/get?key=corpwxUrgentMsgToken";
        return template.getForObject(url, String.class);
    }

    public String getWeComSendFileToken() {
        String url = apiUrl.getScheduledApi() + "/accessToken/get?key=corpwxFilePushToken";
        return template.getForObject(url, String.class);
    }

    public String[] getLisDockSign() {
        String url = apiUrl.getScheduledApi() + "/accessToken/getLisDockSign";
        return template.getForObject(url, String[].class);
    }

    public void setLisDockSign(String[] sign) {
        String url = apiUrl.getScheduledApi() + "/accessToken/setLisDockSign?"
                     + "s1=" + sign[0] + "&s2=" + sign[1];
        template.getForObject(url, String.class);
    }

    public String getThmzToken() {
        String url = apiUrl.getScheduledApi() + "/accessToken/get?key=thmzToken";
        return template.getForObject(url, String.class);
    }

}
