package com.its.op.controller.its.rse;

import com.its.op.controller.its.LoginController;
import com.its.op.dto.its.rse.RseControlDto;
import com.its.op.service.its.rse.RseControlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@Api(tags = "14.RSE-0.제어")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/rse/control")
public class RseControlController {

    private final RseControlService service;
    private final LoginController loginController;

    @ApiOperation(value = "RSE 제어기 리셋", response = RseControlDto.RseControlRes.class)
    @PostMapping(value = "/reset/{id}", produces = {"application/json; charset=utf8"})
    public RseControlDto.RseControlRes controlReset(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "제어정보", example = "", required = true)
            @RequestBody @Valid final RseControlDto.RseControlResetReq req,
            HttpServletRequest request) {
        String userId = this.loginController.getSessionUserId(request);
        log.info("UUID: {}", userId);
        if (!userId.equals("")) {
            req.setUserId(userId);
        }
        req.setDevice(0);
        req.setControl(1);
        return this.service.controlReset(id, req);
    }

}
