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.InstShmtOdrRequest;
import com.oqpo.api.web.dto.request.inoutmng.ShmtOdrTargetGridRequest;
import com.oqpo.api.web.dto.request.inoutmng.ShmtOutSearchGridRequest;
import com.oqpo.api.web.dto.request.pomng.pchOrd.SavePchOrdRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
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)));
    }

}
