package com.xhpc.pp.controller;

import com.alibaba.nacos.api.exception.NacosException;
import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.api.PowerPileService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.down.StartChargingData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private PowerPileService powerPileService;
    @Autowired
    private PileOrderService pileOrderService;

    @GetMapping("test/{pno}/{ono}/{b}/{gid}")
    public R test(@PathVariable String pno, @PathVariable String ono, @PathVariable int b, @PathVariable String gid) throws NacosException {

//        String serverIp = "127.0.0.1";
//        int serverPort = 8848;
//        String serverAddr = serverIp + ":" + serverPort;
//        NamingService namingService = NacosFactory.createNamingService(serverAddr);
//        List<Instance> ppInstances = namingService.getAllInstances("xhpc-power-pile");
        // todo clean dead host pile cache
//        String ipAndPort = GetIpAndPort.getIpAndPort();

        StartChargingData d = new StartChargingData();
        d.setPileNo(pno); //55031412782305
        d.setOrderNo(ono); //00000000000000000000000123456789
        d.setBalance(b); //300
        d.setGunId(gid); //02
        return powerPileService.startCharging(d);
    }

    @GetMapping("rime/{orderNo}/{N}")
    public R test(@PathVariable String orderNo, @PathVariable Integer N) {

        for (int i = 0; i < N; i++) {

            pileOrderService.pileRimeOrder(orderNo);
        }

        return R.ok();
    }
}
