package com.tax.zone.web.controller;

import com.tax.zone.integration.user.UserClient;
import com.tax.zone.model.FinZoneInfo;
import com.tax.zone.model.ZoneModel;
import com.tax.zone.service.api.FinZoneInfoService;
import com.yxcheng.token.common.annotation.LogT;
import com.yxcheng.token.common.model.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
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.List;

@Slf4j
@RestController
@RefreshScope
@RequestMapping("/client")
public class ZoneController {
    @Autowired
    private FinZoneInfoService finZoneInfoService;

    @Value("${config.number}")
    private String userName;

    @Autowired
    private UserClient userClient;

    @RequestMapping(value ="/findAllZoneList" , method = RequestMethod.POST)
    @LogT(LogT.LOG_VIEW_PART)
//    @RuleT(RestFulApiContants.ASYN_COLLECT_CERTIFIED)
    public JsonResult findAllZoneList(@RequestBody ZoneModel zoneModel){
        JsonResult result = new JsonResult();
        List<FinZoneInfo> zoneInfoList = finZoneInfoService.findAllZoneListAndSetCache(zoneModel);
        result.setData(zoneInfoList);
        log.info("findAllZoneList number is : "+ zoneInfoList.size());
        return result;
    }

    @RequestMapping(value ="/getZoneInfoByCode" , method = RequestMethod.POST)
    @LogT
    public JsonResult getZoneInfoByCode(@RequestBody ZoneModel zoneModel){
        JsonResult result = new JsonResult();

        FinZoneInfo zoneInfo = finZoneInfoService.getZoneInfoByCode(zoneModel.getZoneCode());
        result.setData(zoneInfo);
        return result;
    }


    @RequestMapping(value ="/heartbeat" , method = RequestMethod.GET)
    public JsonResult<String> heartbeat(){
        JsonResult result = new JsonResult();
        result.setData(userClient.heartbeat());
        return result;
    }
}
