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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.stockmng.StockCddService;
import com.oqpo.api.web.dto.request.stockmng.*;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.stockmng.StockCddInfoResponse;
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/stock/cdd")
public class StockCddController {

    @Autowired
    private StockCddService stockCddService;

    /**
     * 설명 : 재고실사 그리드 리스트
     *
     * @param stockCddGridRequest
     * @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 StockCddGridRequest stockCddGridRequest) throws Exception {
        return ResponseEntity.ok(stockCddService.selectStockCddGridList(stockCddGridRequest.getSBrandId(), stockCddGridRequest.getSStoreId(), stockCddGridRequest.getSWhsId(),
                stockCddGridRequest.getSLocation(), stockCddGridRequest.getSCddDvsn(), stockCddGridRequest.getFromDt(), stockCddGridRequest.getToDt(),
                stockCddGridRequest.toDTO(stockCddGridRequest)));
    }

    /**
     * 설명 : 재고 실사 저장
     *
     * @param userId
     * @param saveStockCddRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "재고 실사 저장")
    @PostMapping("/save-stock-cdd")
    public ResponseEntity<SaveResponse> saveStockCdd(@ApiIgnore String userId, @RequestBody @Valid SaveStockCddRequest saveStockCddRequest) throws Exception {
        stockCddService.saveStockCdd(userId, saveStockCddRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 재고실사 기본 정보
     *
     * @param cddId
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "cddId", value = "실사아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "재고실사 기본 정보")
    @GetMapping("/info-cdd")
    public ResponseEntity<StockCddInfoResponse> infoCdd(@RequestParam(value = "cddId") String cddId) throws Exception {
        return ResponseEntity.ok(stockCddService.selectStockCddInfo(cddId));
    }

    /**
     * 설명 : 재고실사 품목정보 그리드 리스트
     *
     * @param stockCddDtlGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "재고실사 품목정보 그리드 리스트")
    @PostMapping("/cdd-detail-grid-list")
    public ResponseEntity<GridResponse> cddDetailGridList(@RequestBody @Valid StockCddDtlGridRequest stockCddDtlGridRequest) throws Exception {
        return ResponseEntity.ok(stockCddService.selectStockCddDtlGridList(stockCddDtlGridRequest.getCddId(),
                stockCddDtlGridRequest.toDTO(stockCddDtlGridRequest)));
    }

}
