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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.inoutmng.ColOdrService;
import com.oqpo.api.service.inoutmng.ShmtOdrService;
import com.oqpo.api.web.dto.request.inoutmng.*;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.inoutmng.ColInfoResponse;
import com.oqpo.api.web.dto.response.inoutmng.InvInfoResponse;
import com.oqpo.api.web.dto.response.inoutmng.SpplyInvInitResponse;
import com.oqpo.api.web.dto.response.inoutmng.SpplyPickInitResponse;
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/rtnmng/inoutmng")
@Api(tags = {"수거지시 / 공급사 수거서 생성 관리 (ColOdrController) -- 진행중"})
public class ColOdrController {
    @Autowired
    private ColOdrService colOdrService;


    /**
     * 설명 : 수거지시 대상리스트트 그리 리스트
     *
     * @param colOdrTargetRtnGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 수거지시 대상 그리드 리스트")
    @PostMapping("/col-target-grid-list")
    public ResponseEntity<GridResponse> selectColTargetOdrGridList(@RequestBody @Valid ColOdrTargetRtnGridRequest colOdrTargetRtnGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectColTargetOdrGridList(colOdrTargetRtnGridRequest.getSBrandId(), colOdrTargetRtnGridRequest.getFromDt(), colOdrTargetRtnGridRequest.getToDt(), colOdrTargetRtnGridRequest.getSWhsId(), colOdrTargetRtnGridRequest.getSRtnWhsId(), colOdrTargetRtnGridRequest.getSItemNm(),  colOdrTargetRtnGridRequest.toDTO(colOdrTargetRtnGridRequest)));
    }


    /**
     * 설명 : 수거지시 초기 대상 정보 리스트
     *
     * @param colOdrTargetRtnGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 수거지시 초기정보 리스트\n")
    @PostMapping("/col-inst-inti-grid-list")
    public ResponseEntity<GridResponse> selectColInstOdrGridList(@RequestBody @Valid InstInitColOdrRequest instInitColOdrRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectColInstOdrGridList(instInitColOdrRequest.getBrandId(), instInitColOdrRequest, instInitColOdrRequest.toDTO(instInitColOdrRequest)));
    }

    /**
     * 설명 : 수거지시 정보 저장
     *
     * @param userId
     * @param instShmtOdrRequest
     * @return SaveResponse
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "수거지시 정보 저장")
    @PostMapping("/save-inst-col")
    public ResponseEntity<SaveResponse> instColOdr(@ApiIgnore String userId, @RequestBody @Valid InstColOdrRequest instColOdrRequest) throws Exception {
        colOdrService.instColOdr(userId,  instColOdrRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.COL_OK));
    }

    /**
     * 설명 : 수거현황 그리 리스트
     *
     * @param ShmtOutSearchGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 수거현황 그리 리스트")
    @PostMapping("/colsearch-grid-list")
    public ResponseEntity<GridResponse> selectColSearchGridList(@RequestBody @Valid ColSearchGridRequest colSearchGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectColSearchGridList(colSearchGridRequest.getSBrandId(), colSearchGridRequest.getFromDt(), colSearchGridRequest.getToDt(), colSearchGridRequest.getSColDvsn(), colSearchGridRequest.getSWhsId(), colSearchGridRequest.getSRtnWhsId(),  colSearchGridRequest.getSColCmdDtlStCd(), colSearchGridRequest.getSItemNm(),  colSearchGridRequest.toDTO(colSearchGridRequest)));
    }


    /**
     * 설명 : 수거서정보 정보
     *
     * @param brandId, pickPrtInfoRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "수거서출력 정보")
    @PostMapping("/info-pick")
    public ResponseEntity<ColInfoResponse> infoPick(@RequestBody @Valid PickPrtInfoRequest pickPrtInfoRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectPickInfo(pickPrtInfoRequest.getBrandId(), pickPrtInfoRequest.getColPickUnqNo()));
    }

    /**
     * 설명 : 공급사 납품 대상리스트트 그리 리스트
     *
     * @param spplyRtnTargetGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 공급사 수거서 대상리스트 그리 리스트")
    @PostMapping("/spply-target-rtn-grid-list")
    public ResponseEntity<GridResponse> selectSpplyTargetRtnGridList(@RequestBody @Valid SpplyRtnTargetGridRequest spplyRtnTargetGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectSpplyTargetRtnGridList(spplyRtnTargetGridRequest.getSBrandId(), spplyRtnTargetGridRequest.getFromDt(), spplyRtnTargetGridRequest.getToDt(), spplyRtnTargetGridRequest.getSSpplyId(), spplyRtnTargetGridRequest.getSRtnWhsId(), spplyRtnTargetGridRequest.getSItemNm(),  spplyRtnTargetGridRequest.toDTO(spplyRtnTargetGridRequest)));
    }


    /**
     * 설명 : 공급사 반품데이타 수거서 생성 초기데이타
     *
     * @param brandId, spplyId, rtnPodrUnqNo
     * @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"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "rtnPodrUnqNo", value = "반품발주번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "공급사 반품발주데이타 수거서 생성 초기데이타")
    @GetMapping("/init-spply-col")
    public ResponseEntity<SpplyPickInitResponse> selectSpplyShmtOdrInfo(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "spplyId") String spplyId, @RequestParam(value = "rtnPodrUnqNo") String rtnPodrUnqNo) throws Exception {
        return ResponseEntity.ok(colOdrService.selectSpplyShmtOdrInfo(brandId,spplyId, rtnPodrUnqNo));
    }

    /**
     * 설명 : 공급사 수거서 생성 저장
     *
     * @param userId
     * @param instShmtOdrRequest
     * @return SaveResponse
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "공급사 수거서 생성 저장 저장")
    @PostMapping("/save-spply-col")
    public ResponseEntity<SaveResponse> saveSpplyPick(@ApiIgnore String userId, @RequestBody @Valid SaveSpplyPickRequest saveSpplyPickRequest) throws Exception {
        colOdrService.saveSpplyPick(userId,  saveSpplyPickRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


    /**
     * 설명 : 공급사 수거서 현황 그리드 리스트
     *
     * @param SpplyDeliDtlGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 공급사 - 수거서 현황 그리드 리스트")
    @PostMapping("/spply-pick-grid-list")
    public ResponseEntity<GridResponse> selectSpplyDeliGridList(@RequestBody @Valid SpplyPickDtlGridRequest spplyPickDtlGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectSpplyPickGridList(spplyPickDtlGridRequest.getSBrandId(), spplyPickDtlGridRequest.getFromDt(), spplyPickDtlGridRequest.getToDt(),  spplyPickDtlGridRequest.getSSpplyId(), spplyPickDtlGridRequest.getSWhsId(), spplyPickDtlGridRequest.getSItemNm(),  spplyPickDtlGridRequest.toDTO(spplyPickDtlGridRequest)));
    }

    /**
     * 설명 : 반품처리 대상 리스트
     *
     * @param SpplyDeliDtlGridRequest
     * @return
     * @throws Exception

     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 반품처리 대상 그리드 리스트")
    @PostMapping("/retstock-target-grid-list")
    public ResponseEntity<GridResponse> selectRtnStockTargetList(@ApiIgnore String userId, @RequestBody @Valid RtnStockTragetGridRequest rtnStockTragetGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectRtnStockTargetList(userId, rtnStockTragetGridRequest.getSBrandId(),rtnStockTragetGridRequest.getSStoreId(), rtnStockTragetGridRequest.getSColPickUnqNo(),   rtnStockTragetGridRequest.getFromDt(), rtnStockTragetGridRequest.getToDt(), rtnStockTragetGridRequest.getSRtnWhsId(), rtnStockTragetGridRequest.getSSpplyId(), rtnStockTragetGridRequest.getSWhsId(), rtnStockTragetGridRequest.getSItemNm(),  rtnStockTragetGridRequest.toDTO(rtnStockTragetGridRequest)));
    }


    /**
     * 설명 : 반품처리
     *
     * @param userId
     * @param instShmtOdrRequest
     * @return SaveResponse
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "반품처리 저장")
    @PostMapping("/save-retstock")
    public ResponseEntity<SaveResponse> saveRtnStockProc(@ApiIgnore String userId, @RequestBody @Valid SaveRtnStockProcRequest saveRtnStockProcRequest) throws Exception {
        colOdrService.saveRtnStockProc(userId,  saveRtnStockProcRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.RTN_PROC_OK));
    }


    /**
     * 설명 : 반품처리 현황 리스트
     *
     * @param RtnStockTragetGridRequest
     * @return
     * @throws Exception

     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 반품처리 현황 그리드 리스트")
    @PostMapping("/retstock-result-grid-list")
    public ResponseEntity<GridResponse> selectRtnStockResultList(@RequestBody @Valid RtnStockResultGridRequest rtnStockResultGridRequest) throws Exception {
        return ResponseEntity.ok(colOdrService.selectRtnStockResultList(rtnStockResultGridRequest.getSBrandId(),rtnStockResultGridRequest.getSStoreId(), rtnStockResultGridRequest.getSColPickUnqNo(), rtnStockResultGridRequest.getFromDt(), rtnStockResultGridRequest.getToDt(), rtnStockResultGridRequest.getSRtnWhsId(), rtnStockResultGridRequest.getSSpplyId(), rtnStockResultGridRequest.getSWhsId(), rtnStockResultGridRequest.getSItemNm(), rtnStockResultGridRequest.getSRtnPodrUnqNo(),  rtnStockResultGridRequest.toDTO(rtnStockResultGridRequest)));
    }

    /**
     * 설명 : 입고 현황 그리드 리스트
     *
     * @param DeliDtlGridRequest
     * @return
     * @throws Exception


    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 입고 현황 그리드 리스트")
    @PostMapping("/save-retstock")
    public ResponseEntity<GridResponse> selectWarehouseGridList(@RequestBody @Valid WarehouseGridRequest warehouseGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectWarehouseGridList(warehouseGridRequest.getSBrandId(), warehouseGridRequest.getSStoreId(), warehouseGridRequest.getFromDt(), warehouseGridRequest.getToDt(), warehouseGridRequest.getSPchPodrUnqNo(),  warehouseGridRequest.getSSpplyId(), warehouseGridRequest.getSWhsId(), warehouseGridRequest.getSItemNm(),  warehouseGridRequest.toDTO(warehouseGridRequest)));
    }
     */
}
