package com.malk.aipocloud.controller;

/**
 * 错误抛出与拦截详见 CatchException
 */

import com.malk.aipocloud.repository.dao.ABEventDao;
import com.malk.aipocloud.service.ABClient;
import com.malk.delegate.McDelegate;
import com.malk.server.common.McR;
import com.malk.utils.UtilDateTime;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping
public class ABController {

    @Autowired
    private ABClient abClient;

    @Autowired
    private ABEventDao abEventDao;

    /**
     * 同步审批单
     */
    @PostMapping("process/sync")
    McR syncProcess() {

        abClient.syncProcess(UtilDateTime.parseLocalDateTime("2023-11-29 00:00:00"), UtilDateTime.parseLocalDateTime("2023-11-29 23:59:59"));
//        LocalDateTime now = LocalDateTime.now().minusHours(8);
//        abClient.syncProcess(now.minusMinutes(5), now);
        return McR.success();
    }

    /**
     * 通讯录同步
     */
    @Synchronized
    @PostMapping("contact/sync")
    McR syncContact() {

        log.info("手动触发, 通讯录同步");
        abClient.syncContact();
        return McR.success();
    }


    @Autowired
    private McDelegate mcDelegate;

    @Value("${server.ssl.key-store}")
    private String keyStore;

    @Value("${server.ssl.key-store-password}")
    private String keyStorePassword;

    @GetMapping("test")
    McR test() {

        log.info("11111, {}, {}", keyStore, keyStorePassword);

        mcDelegate.setTimeout(() -> {

            log.info("22222");
        }, 5000);
        return McR.success();
    }
}
