package com.zhongshu.card.server.core.controller.org;

import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.test.TestUserInfoParam;
import com.zhongshu.card.client.model.test.TestUserParam;
import com.zhongshu.card.client.utils.DateUtils;
import com.zhongshu.card.server.core.service.TestService;
import com.zhongshu.card.server.core.service.devices.DeviceInfoServiceImpl;
import com.zhongshu.card.server.core.service.openAPI.OpenAPIRegisterService;
import com.zhongshu.card.server.core.service.payment.PayCallService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;

@Slf4j
@RestController
@RequestMapping("test")
@Tag(name = "测试")
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    OpenAPIRegisterService openAPIRegisterService;

    @Autowired
    DeviceInfoServiceImpl deviceInfoService;

    @Autowired
    private PayCallService payCallService;

    @Operation(summary = "测试接口", description = "测试接口")
    @RequestMapping(value = "text", method = {RequestMethod.GET})
    public ResultContent text() {
        openAPIRegisterService.initRegisterPAIS();
        try {
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.testService.text();
    }

    @Operation(summary = "测试用户同步", description = "测试隐患同步")
    @RequestMapping(value = "testAddUser", method = {RequestMethod.POST})
    public ResultContent testAddUser(@RequestBody TestUserParam param) {
        log.info("testAddUser... {} {}", param.getList().size(),
                DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
        return ResultContent.buildSuccess();
    }

    @Operation(summary = "测试用户同步（From）", description = "测试隐患同步")
    @RequestMapping(value = "testAddUser1", method = {RequestMethod.POST})
    public ResultContent testAddUser1(@Parameter TestUserInfoParam param) {
        log.info("testAddUser1... {}", param.getNickname());
        return ResultContent.buildSuccess();
    }

    public static byte[] reverse(byte[] bin) {
        var items = new ArrayList<Byte>();
        for (var b : bin) {
            items.add(b);
        }
        Collections.reverse(items);
        byte[] ret = new byte[items.size()];
        for (int i = 0; i < items.size(); i++) {
            ret[i] = items.get(i);
        }
        return ret;
    }

}
