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

import com.oqpo.api.enums.DataMessageCode;
import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.oper.AfflService;
import com.oqpo.api.service.stinfo.SpplyService;
import com.oqpo.api.web.dto.request.oper.affl.AfflGridRequest;
import com.oqpo.api.web.dto.request.oper.affl.AfflShopBaseInfoGridRequest;
import com.oqpo.api.web.dto.request.oper.affl.SaveAfflRequest;
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.DataResponse;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.oper.affl.AfflShopInfoResponse;
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/spply")
public class SpplyController {
    @Autowired
    private SpplyService spplyService;

    /**
     * 설명 : 공급사 팝업 그리드 리스트
     *
     * @param SpplyPopGridRequest
     * @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> spplyPopGridList( @RequestBody @Valid SpplyPopGridRequest spplyPopGridRequest) throws Exception {
        return ResponseEntity.ok(spplyService.selectPopSpplyGridList(spplyPopGridRequest.getSBrandId(), spplyPopGridRequest.getSSpplyNm(), spplyPopGridRequest.toDTO(spplyPopGridRequest)) );
    }

    /**
     * 설명 : 공급사 그리드 리스트
     *
     * @param SpplyGridRequest
     * @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 SpplyGridRequest spplyGridRequest) throws Exception {
        return ResponseEntity.ok(spplyService.selectSpplyGridList( spplyGridRequest.getSBrandId(), spplyGridRequest.getSStCd(), spplyGridRequest.getSBsnsRegNo(), spplyGridRequest.getSSpplyNm(),  spplyGridRequest.toDTO(spplyGridRequest)));
    }


    /**
     * 설명 : 공급사 정보
     *
     * @param afflShopId
     * @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")
    })
    @ApiOperation(value = "공급사 정보")
    @GetMapping("/info-spply")
    public ResponseEntity<SpplyInfoResponse> infoSpply(@RequestParam(value = "brandId") String brandId,@RequestParam(value = "spplyId") String spplyId) throws Exception {
        return ResponseEntity.ok(spplyService.selectSpplyInfo(brandId,spplyId));
    }


    /**
     * 설명 : 공급사 정보 저장
     *
     * @param userId
     * @param SaveSpplyRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "공급사정보 저장")
    @PostMapping("/save-spply")
    public ResponseEntity<SaveResponse> saveCode(@ApiIgnore String userId, @RequestBody @Valid SaveSpplyRequest saveSpplyRequest) throws Exception {
        spplyService.saveSpplyList(userId, saveSpplyRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


    /**
     * 설명 : 공급사 패스워드 초기화
     *
     * @param userId
     * @param
     * @return SaveResponse
     * @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")
    })
    @ApiOperation(value = "공급사 패스워드 초기화")
    @GetMapping("/inti-spplyPw")
    public ResponseEntity<SaveResponse> initSpplyPw(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "spplyId") String spplyId) throws Exception {
        spplyService.updateSpplyInitPw(brandId,spplyId);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.INIT_PW_OK));
    }

}
