package com.friday.tooldriver.controller.external;

import com.friday.base.common.response.DubboResult;
import com.friday.base.web.response.ResponseAspect;
import com.friday.operation.api.distributor.dto.StandardRpaInput;
import com.friday.operation.api.keepalive.dto.smartrpa.HeartbeatReq;
import com.friday.operation.api.keepalive.dto.smartrpa.HeartbeatResp;
import com.friday.operation.api.tooldriver.service.ISmartRPAHeartbeatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/driver/smart-rpa/execute")
@Slf4j
public class SmartRpaHeartbeatController {

    @Autowired
    private ResponseAspect responseAspect;
    @Autowired
    private ISmartRPAHeartbeatService heartbeatService;

    
    @RequestMapping(value = "/heartbeat", method = RequestMethod.POST)
    public Object heartbeat(@RequestBody HeartbeatReq heartBeat) {
        DubboResult<HeartbeatResp> result = heartbeatService.heartbeat(heartBeat);
        if (result.success()){
            return this.responseAspect.success(result.getObject());
        } else {
            return this.responseAspect.fail(result.getMessage());
        }
    }

    
    @RequestMapping(value = "/jobDetail", method = RequestMethod.GET)
    public Object queryJobDetail(@RequestParam(name = "jobId") String jobId) {
        DubboResult<StandardRpaInput> result = heartbeatService.getJobDetail(jobId);
        if (result.success()){
            return this.responseAspect.success(result.getObject());
        } else {
            return this.responseAspect.fail(result.getMessage());
        }
    }
}