package com.oqpo.api.web.controller.stockmng;

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.stockmng.DmandFrcstService;
import com.oqpo.api.web.dto.request.stockmng.*;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.stockmng.DmandFrcstInfoResponse;
import com.oqpo.api.web.dto.response.stockmng.StatusDmandFrcstResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/dmand/frcst")
@Api(tags = {"수요예측 (DmandFrcstController)"})
public class DmandFrcstController {

    @Autowired
    private DmandFrcstService dmandFrcstService;

    /**
     * 설명 : 수요예측기준정보 조회
     *
     * @param brandId
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "brandId", value = "브랜드아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "수요예측기준정보 조회")
    @GetMapping("/info-dmand-frcst")
    public ResponseEntity<DmandFrcstInfoResponse> infoDmandFrcst(@RequestParam(value = "brandId") String brandId) throws Exception {
        return ResponseEntity.ok(dmandFrcstService.selectDmandFrcstInfo(brandId));
    }

    /**
     * 설명 : 수요예측기준정보 저장
     *
     * @param userId
     * @param saveDmandFrcstInfoRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "수요예측기준정보 저장")
    @PostMapping("/save-dmand-frcst")
    public ResponseEntity<SaveResponse> saveDmandFrcst(@ApiIgnore String userId, @RequestBody @Valid SaveDmandFrcstInfoRequest saveDmandFrcstInfoRequest) throws Exception {
        dmandFrcstService.saveDmandFrcstInfo(userId, saveDmandFrcstInfoRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 수요예측현황
     *
     * @param userId
     * @param statusDmandFrcstInfoRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "수요예측현황")
    @PostMapping("/status-dmand-frcst")
    public ResponseEntity<StatusDmandFrcstResponse> statusDmandFrcst(@ApiIgnore String userId, @RequestBody @Valid StatusDmandFrcstRequest statusDmandFrcstInfoRequest) throws Exception {
        return ResponseEntity.ok(dmandFrcstService.selectDmandFrcstStatus(statusDmandFrcstInfoRequest));
    }

}
