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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.stockmng.StockBaseMngService;
import com.oqpo.api.service.stockmng.StockMngService;
import com.oqpo.api.web.dto.request.stockmng.SaveStockBaseInfoRequest;
import com.oqpo.api.web.dto.request.stockmng.StockBaseMngGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/stock/base/mng")
public class StockBaseMngController {

    @Autowired
    private StockMngService stockMngService;

    @Autowired
    private StockBaseMngService stockBaseMngService;

    /**
     * 설명 : 재고기준정보관리 그리드 리스트
     *
     * @param stockBaseMngGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "재고기준정보관리 그리드 리스트")
    @PostMapping("/detail-grid-list")
    public ResponseEntity<GridResponse> detailGridList(@RequestBody @Valid StockBaseMngGridRequest stockBaseMngGridRequest) throws Exception {
        return ResponseEntity.ok(stockMngService.selectStockMngGridList(stockBaseMngGridRequest.getSBrandId(), stockBaseMngGridRequest.getSStoreId(),
                stockBaseMngGridRequest.getSWhsId(), stockBaseMngGridRequest.getSLocation(),
                stockBaseMngGridRequest.getSItemClass1(), stockBaseMngGridRequest.getSItemClass2(), stockBaseMngGridRequest.getSItemClass3(), stockBaseMngGridRequest.getSItemClass4(),
                stockBaseMngGridRequest.getSItemId(), stockBaseMngGridRequest.getSItemNm(), stockBaseMngGridRequest.toDTO(stockBaseMngGridRequest)));
    }

    /**
     * 설명 : 재고기준정보 저장
     *
     * @param userId
     * @param saveStockBaseInfoRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "재고기준정보 저장")
    @PostMapping("/save")
    public ResponseEntity<SaveResponse> save(@ApiIgnore String userId, @RequestBody @Valid SaveStockBaseInfoRequest saveStockBaseInfoRequest) throws Exception {
        stockBaseMngService.saveStockBaseInfo(userId, saveStockBaseInfoRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

}
