package com.fs.wxwork.service;

import com.alibaba.fastjson.TypeReference;
import com.fs.wxwork.dto.*;
import com.fs.wxwork.utils.WxWorkHttpUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class WxWorkServiceImpl implements WxWorkService {
    /**
     * 基础地址
     */
    //private static final String BASE_URL = "http://47.94.7.218:8089/wxwork";


    private static final String BASE_URL = "http://47.109.179.95:8083/wxwork";
    @Override
    public WxWorkResponseDTO<WxWorkInitRespDTO> init(WxWorkInitDTO param) {
        String url = BASE_URL + "/init";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkInitRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO SetCallbackUrl(WxWorkSetCallbackUrlDTO param) {
        String url = BASE_URL + "/SetCallbackUrl";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxWorkSendTextMsgRespDTO> SendTextMsg(WxWorkSendTextMsgDTO param) {
        String url = BASE_URL + "/SendTextMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkSendTextMsgRespDTO>>() {
        });
    }

    @Override
    public WxWorkSendAppMsgRespDTO SendAppMsg(WxWorkSendAppMsgDTO param) {
        String url = BASE_URL + "/SendAppMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkSendAppMsgRespDTO>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwSendLinkMsgRespDTO> SendLinkMsg(WxwSendLinkMsgDTO param) {
        String url = BASE_URL + "/SendLinkMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendLinkMsgRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxWorkGetQrCodeRespDTO> getQrCode(WxWorkGetQrCodeDTO param) {
        String url = BASE_URL + "/getQrCode";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxWorkGetQrCodeRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO<List<WxwGetExternalContactRespDTO>> getExternalContacts(WxwGetExternalContactsDTO param) {
        String url = BASE_URL + "/GetExternalContacts";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<List<WxwGetExternalContactRespDTO>>>() {
        });
    }

    @Override
    public WxWorkResponseDTO CheckCode(WxWorkCheckCodeDTO param) {
        String url = BASE_URL + "/CheckCode";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwSecondaryValidationRespDTO> SecondaryValidation(WxWorkGetQrCodeDTO param) {
        String url = BASE_URL + "/SecondaryValidation";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSecondaryValidationRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO automaticLogin(WxWorkGetQrCodeDTO param) {
        String url = BASE_URL + "/automaticLogin";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwLoginOutRespDTO> LoginOut(WxWorkGetQrCodeDTO param) {
        String url = BASE_URL + "/LoginOut";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwLoginOutRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwMarkAsReadRespDTO> MarkAsRead(WxwMarkAsReadDTO param) {
        String url = BASE_URL + "/MarkAsRead";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwMarkAsReadRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwSendGroupsMsgRespDTO> SendGroupsMsg(WxwSendGroupsMsgDTO param) {
        String url = BASE_URL + "/SendGroupsMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendGroupsMsgRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO<WxwGetRunClientRespDTO> getRunClient() {
        String url = BASE_URL + "/GetRunClient";
        return WxWorkHttpUtil.postWithType(url, null, new TypeReference<WxWorkResponseDTO<WxwGetRunClientRespDTO>>() {
        });
    }

    @Override
    public WxWorkResponseDTO RevokeMsg(WxwRevokeMsgDTO param) {
        String url = BASE_URL + "/RevokeMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendCDNImgMsgRespDTO> SendCDNImgMsg(WxwSendCDNImgMsgDTO param) {
        String url = BASE_URL + "/SendCDNImgMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNImgMsgRespDTO>>() {});

    }

    @Override
    public WxWorkResponseDTO<WxwSendCDNFileMsgRespDTO> SendCDNFileMsg(WxwSendCDNFileMsgDTO param) {
        String url = BASE_URL + "/SendCDNFileMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNFileMsgRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO> SendCDNVoiceMsg(WxwSendCDNVoiceMsgDTO param) {
        String url = BASE_URL + "/SendCDNVoiceMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVoiceMsgRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendCDNVideoMsgRespDTO> SendCDNVideoMsg(WxwSendCDNVideoMsgDTO param) {
        String url = BASE_URL + "/SendCDNVideoMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNVideoMsgRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendVideoNumberRespDTO> sendVideoNumber(WxwSendVideoNumberDTO param) {
        String url = BASE_URL + "/SendVideoNumber";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendVideoNumberRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendEmotionMessageRespDTO> SendEmotionMessage(WxwSendEmotionMessageDTO param) {
        String url = BASE_URL + "/SendEmotionMessage";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendEmotionMessageRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendBusinessCardMsgRespDTO> SendBusinessCardMsg(WxwSendBusinessCardMsgDTO param) {
        String url = BASE_URL + "/SendBusinessCardMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendBusinessCardMsgRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendLocationMsgRespDTO> SendLocationMsg(WxwSendLocationMsgDTO param) {
        String url = BASE_URL + "/SendLocationMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendLocationMsgRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendTextAtMsgTwoRespDTO> sendTextAtMsgTwo(WxwSendTextAtMsgTwoDTO param) {
        String url = BASE_URL + "/SendTextAtMsgTwo";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendTextAtMsgTwoRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSyncAllDataRespDTO> syncAllData(WxwSyncAllDataDTO param) {
        String url = BASE_URL + "/SyncAllData";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSyncAllDataRespDTO>>() {});
    }

    @Override
    public WxWorkResponseDTO<WxwSendCDNBigVideoMsgRespDTO> SendCDNBigVideoMsg(WxwSendCDNBigVideoMsgDTO param) {
        String url = BASE_URL + "/SendCDNBigVideoMsg";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<WxwSendCDNBigVideoMsgRespDTO>>() {});
    }

    public WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>> Vid2UserId(WxWorkVid2UserIdDTO param) {
        String url = BASE_URL + "/Vid2UserId";
        return WxWorkHttpUtil.postWithType(url, param, new TypeReference<WxWorkResponseDTO<List<WxWorkVid2UserIdRespDTO>>>() {});
    }
}
