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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.inoutmng.ShmtOdrService;
import com.oqpo.api.web.dto.request.inoutmng.*;
import com.oqpo.api.web.dto.request.pomng.pchOrd.SpplyOdrPoGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.inoutmng.InvInfoResponse;
import com.oqpo.api.web.dto.response.inoutmng.SpplyInvInitResponse;
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/pomng/inoutmng")
@Api(tags = {"출하지시 / 공급사 납품서 생성 관리 (ShmtOdrController) -- 진행중"})
public class ShmtOdrController {
    @Autowired
    private ShmtOdrService shmtOdrService;


    /**
     * 설명 : 출하지시 대상리스트트 그리 리스트
     *
     * @param ShmtOdrTargetGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 출하지시 대상리스트트 그리 리스트")
    @PostMapping("/target-grid-list")
    public ResponseEntity<GridResponse> selectShmtTargetOdrGridList(@RequestBody @Valid ShmtOdrTargetGridRequest shmtOdrTargetGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectShmtTargetOdrGridList(shmtOdrTargetGridRequest.getSBrandId(), shmtOdrTargetGridRequest.getFromDt(), shmtOdrTargetGridRequest.getToDt(), shmtOdrTargetGridRequest.getSShmtWhsId(), shmtOdrTargetGridRequest.getSWhsId(), shmtOdrTargetGridRequest.getSItemNm(),  shmtOdrTargetGridRequest.toDTO(shmtOdrTargetGridRequest)));
    }

    /**
     * 설명 : 출하지시 정보 저장
     *
     * @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-shmt")
    public ResponseEntity<SaveResponse> instShmtOdr(@ApiIgnore String userId, @RequestBody @Valid InstShmtOdrRequest instShmtOdrRequest) throws Exception {
        shmtOdrService.instShmtOdr(userId,  instShmtOdrRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

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

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 출하현황 그리 리스트")
    @PostMapping("/outsearch-grid-list")
    public ResponseEntity<GridResponse> selectShmtOutSearchGridList(@RequestBody @Valid ShmtOutSearchGridRequest shmtOutSearchGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectShmtSearchGridList(shmtOutSearchGridRequest.getSBrandId(), shmtOutSearchGridRequest.getFromDt(), shmtOutSearchGridRequest.getToDt(), shmtOutSearchGridRequest.getSShmtWhsId(), shmtOutSearchGridRequest.getSShmtReqStCd(),  shmtOutSearchGridRequest.getSWhsId(), shmtOutSearchGridRequest.getSItemNm(),  shmtOutSearchGridRequest.toDTO(shmtOutSearchGridRequest)));
    }


    /**
     * 설명 : 납품서정보 정보
     *
     * @param brandId, dlvSttmtUnqNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "납품서출력 정보")
    @PostMapping("/info-inv")
    public ResponseEntity<InvInfoResponse> infoInv(@RequestBody @Valid DeliPrtInfoRequest deliPrtInfoRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectInvInfo(deliPrtInfoRequest.getBrandId(), deliPrtInfoRequest.getDlvSttmtUnqNo()));
    }

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

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 공급사 납품 대상리스트 그리 리스트")
    @PostMapping("/spply-target-grid-list")
    public ResponseEntity<GridResponse> selectSpplyTargetOdrGridList(@RequestBody @Valid SpplyOdrTargetGridRequest spplyOdrTargetGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectSpplyTargetOdrGridList(spplyOdrTargetGridRequest.getSBrandId(), spplyOdrTargetGridRequest.getFromDt(), spplyOdrTargetGridRequest.getToDt(), spplyOdrTargetGridRequest.getSSpplyId(), spplyOdrTargetGridRequest.getSWhsId(), spplyOdrTargetGridRequest.getSItemNm(),  spplyOdrTargetGridRequest.toDTO(spplyOdrTargetGridRequest)));
    }


    /**
     * 설명 : 공급사 발주데이타 납품서 생성 초기데이타
     *
     * @param brandId, dlvSttmtUnqNo
     * @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 = "pchPodrUnqNo", value = "구매발주번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "공급사 발주데이타 납품서 생성 초기데이타")
    @GetMapping("/init-spply-inv")
    public ResponseEntity<SpplyInvInitResponse> initSpplyInv(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "spplyId") String spplyId, @RequestParam(value = "pchPodrUnqNo") String pchPodrUnqNo) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectSpplyShmtOdrInfo(brandId,spplyId, pchPodrUnqNo));
    }

    /**
     * 설명 : 공급사 납품서 생성 저장
     *
     * @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-inv")
    public ResponseEntity<SaveResponse> saveSpplyInv(@ApiIgnore String userId, @RequestBody @Valid SaveSpplyDlvRequest saveSpplyDlvRequest) throws Exception {
        shmtOdrService.saveSpplyInv(userId,  saveSpplyDlvRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


    /**
     * 설명 : 납품서 현황 그리드 리스트
     *
     * @param DeliDtlGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 납품서 현황 그리드 리스트")
    @PostMapping("/deli-grid-list")
    public ResponseEntity<GridResponse> selectDeliGridList(@RequestBody @Valid DeliDtlGridRequest deliDtlGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectDeliGridList(deliDtlGridRequest.getSBrandId(), deliDtlGridRequest.getDtlGubun(), deliDtlGridRequest.getFromDt(), deliDtlGridRequest.getToDt(), deliDtlGridRequest.getSDlvStCd(),  deliDtlGridRequest.getSSpplyId(), deliDtlGridRequest.getSWhsId(), deliDtlGridRequest.getSItemNm(),  deliDtlGridRequest.toDTO(deliDtlGridRequest)));
    }

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

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

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

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 입고처리 대상 그리드 리스트")
    @PostMapping("/warehouse-target-grid-list")
    public ResponseEntity<GridResponse> selectSpplyDeliGridList(@RequestBody @Valid WarehouseTragetGridRequest warehouseTragetGridRequest) throws Exception {
        return ResponseEntity.ok(shmtOdrService.selectWarehouseTargetList(warehouseTragetGridRequest.getSBrandId(), warehouseTragetGridRequest.getFromDt(), warehouseTragetGridRequest.getToDt(), warehouseTragetGridRequest.getSWhsId(), warehouseTragetGridRequest.getSSpplyId(), warehouseTragetGridRequest.getSDlvSttmtUnqNo(), warehouseTragetGridRequest.getSItemNm(),  warehouseTragetGridRequest.toDTO(warehouseTragetGridRequest)));
    }


    /**
     * 설명 : 입고처리
     *
     * @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-warehouse")
    public ResponseEntity<SaveResponse> instShmtOdr(@ApiIgnore String userId, @RequestBody @Valid SaveWarehouseProcRequest saveWarehouseProcRequest) throws Exception {
        shmtOdrService.saveWarehouseProc(userId,  saveWarehouseProcRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


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

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 입고 현황 그리드 리스트")
    @PostMapping("/warehouse-grid-list")
    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)));
    }
}
