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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.stinfo.ItemService;
import com.oqpo.api.service.stinfo.SpplyService;
import com.oqpo.api.web.dto.request.stinfo.item.*;
import com.oqpo.api.web.dto.request.stinfo.spply.SaveSpplyRequest;
import com.oqpo.api.web.dto.request.stinfo.spply.SpplyGridRequest;
import com.oqpo.api.web.dto.request.stinfo.spply.SpplyPopGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.stinfo.item.ItemClassMngInfoResponse;
import com.oqpo.api.web.dto.response.stinfo.item.ItemInfoResponse;
import com.oqpo.api.web.dto.response.stinfo.spply.SpplyInfoResponse;
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/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    /**
     * 설명 : 품목 팝업 그리드 리스트
     *
     * @param ItemPopGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 품목 팝업 그리드 리스트")
    @PostMapping("/pop-grid-list")
    public ResponseEntity<GridResponse> selectPopItemGridList( @RequestBody @Valid ItemPopGridRequest itemPopGridRequest) throws Exception {
        return ResponseEntity.ok(itemService.selectPopItemGridList(itemPopGridRequest.getSBrandId(), itemPopGridRequest.getSPodrPssblDvsn(), itemPopGridRequest.getSItemNm(), itemPopGridRequest.toDTO(itemPopGridRequest)) );
    }

    /**
     * 설명 : 품목 그리드 리스트
     *
     * @param itemGridRequest
     * @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 ItemGridRequest itemGridRequest) throws Exception {
        return ResponseEntity.ok(itemService.selectItemGridList( itemGridRequest.getSBrandId(), itemGridRequest.getSItemStCd(), itemGridRequest.getSPodrPssblDvsn(), itemGridRequest.getSItemType(), itemGridRequest.getSItemGubun(), itemGridRequest.getSClass1(), itemGridRequest.getSClass2(), itemGridRequest.getSClass3(), itemGridRequest.getSClass4(), itemGridRequest.getSItemNm(),  itemGridRequest.toDTO(itemGridRequest)));
    }


    /**
     * 설명 : 품목 정보
     *
     * @param itemId
     * @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 = "itemId", value = "품목아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "품목 정보")
    @GetMapping("/info-item")
    public ResponseEntity<ItemInfoResponse> infoItem(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "itemId") String itemId) throws Exception {
        return ResponseEntity.ok(itemService.selectItemInfo(brandId,itemId));
    }


    /**
     * 설명 : 품목 정보 저장
     *
     * @param userId
     * @param saveItemInfolRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "품목 저장")
    @PostMapping("/save-item")
    public ResponseEntity<SaveResponse> saveItem(@ApiIgnore String userId, @RequestBody @Valid SaveItemInfolRequest saveItemInfolRequest) throws Exception {
        itemService.saveItemInfo(userId, saveItemInfolRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


    /**
     * 설명 : 품목분류 그리드 리스트
     *
     * @param itemGridRequest
     * @return
     * @throws Exception
     */

    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = " 품목분류 그리드 리스트")
    @PostMapping("/itemclass-grid-list")
    public ResponseEntity<GridResponse> itemClassGridList(@RequestBody @Valid ItemClassGridRequest itemClassGridRequest) throws Exception {
        return ResponseEntity.ok(itemService.selectItemClassMngGridList(itemClassGridRequest.getSBrandId(), itemClassGridRequest.getSItemClass1(), itemClassGridRequest.getSItemClass2(), itemClassGridRequest.getSItemClass3(), itemClassGridRequest.getSItemClass4(), itemClassGridRequest.getSItemClassNm(),  itemClassGridRequest.toDTO(itemClassGridRequest)));
    }


    //selectItemClassMngInfo
    /**
     * 설명 : 품목 정보
     *
     * @param itemId
     * @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 = "itemClassMgnNo", value = "품목분류번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "품목분류 정보")
    @GetMapping("/info-itemClassMng")
    public ResponseEntity<ItemClassMngInfoResponse> infoItemClassMng(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "itemClassMgnNo") String itemClassMgnNo) throws Exception {
        return ResponseEntity.ok(itemService.selectItemClassMngInfo(brandId,itemClassMgnNo));
    }


    /**
     * 설명 : 품목 정보 저장
     *
     * @param userId
     * @param saveItemClassMngInfolRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "품목분류정보 저장")
    @PostMapping("/save-itemClassMng")
    public ResponseEntity<SaveResponse> saveItemClassMng(@ApiIgnore String userId, @RequestBody @Valid SaveItemClassMngInfolRequest saveItemClassMngInfolRequest) throws Exception {
        itemService.saveItemClassMngInfo(userId, saveItemClassMngInfolRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


    /**
     * 설명 : 품목 분류 삭제
     *
     * @param userId
     * @param DelItemInfolRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "품목분류 삭제")
    @PostMapping("/del-itemClassMng")
    public ResponseEntity<SaveResponse> saveItemClassMng(@ApiIgnore String userId, @RequestBody @Valid DelItemInfolRequest delItemInfolRequest) throws Exception {
        itemService.delItemClassMngInfo(userId, delItemInfolRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }
}
