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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.stinfo.BrandService;
import com.oqpo.api.service.stinfo.StoreBaseInfoService;
import com.oqpo.api.web.dto.request.stinfo.brand.BrandGridRequest;
import com.oqpo.api.web.dto.request.stinfo.brand.BrandSearchGridRequest;
import com.oqpo.api.web.dto.request.stinfo.brand.SaveBrandInfolRequest;
import com.oqpo.api.web.dto.request.stinfo.store.SaveStoreInfolRequest;
import com.oqpo.api.web.dto.request.stinfo.store.StorePopGridRequest;
import com.oqpo.api.web.dto.request.stinfo.store.StoreSearchGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.stinfo.brand.AfflBrandSearchResponse;
import com.oqpo.api.web.dto.response.stinfo.brand.BrandInfoResponse;
import com.oqpo.api.web.dto.response.stinfo.store.StoreInfoResponse;
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/store")
public class StoreController {
    @Autowired
    private StoreBaseInfoService storeBaseInfoService;

    /**
     * 설명 : 팝업 매장 그리드 리스트
     *
     * @param StorePopGridRequest
     * @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> brandPopGridList(@RequestBody @Valid StorePopGridRequest storePopGridRequest) throws Exception {
        return ResponseEntity.ok(storeBaseInfoService.selectPopBrandGridList(storePopGridRequest.getBrandId(), storePopGridRequest.getStoreNm(), storePopGridRequest.toDTO(storePopGridRequest)));
    }



    /**
     * 설명 : 매장 그리드 리스트
     *
     * @param storeSearchGridRequest
     * @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 StoreSearchGridRequest storeSearchGridRequest) throws Exception {
        return ResponseEntity.ok(storeBaseInfoService.selectStoreGridList(storeSearchGridRequest.getSBrandId(), storeSearchGridRequest.getSearchDateType(), storeSearchGridRequest.getFromDt(), storeSearchGridRequest.getToDt(), storeSearchGridRequest.getSStoreDvsn(), storeSearchGridRequest.getSStoreStCd(), storeSearchGridRequest.getSLoanDvsn(), storeSearchGridRequest.getSStoreNm(), storeSearchGridRequest.toDTO(storeSearchGridRequest)));
    }



    /**
     * 설명 : 매장 정보
     *
     * @param brandId, storeId
     * @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 = "storeId", value = "매장아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "매장 정보")
    @GetMapping("/info-store")
    public ResponseEntity<StoreInfoResponse> infoBrand(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "storeId") String storeId) throws Exception {
        return ResponseEntity.ok(storeBaseInfoService.selectStoreInfo(brandId, storeId));
    }


    /**
     * 설명 : 브랜드 정보 저장
     *
     * @param userId
     * @param SaveStoreInfolRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "매장정보  저장")
    @PostMapping("/save-store")
    public ResponseEntity<SaveResponse> saveBrand(@ApiIgnore String userId, @RequestBody @Valid SaveStoreInfolRequest saveStoreInfolRequest) throws Exception {
        storeBaseInfoService.saveStoreInfo(userId, saveStoreInfolRequest);
        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 = "storeId", value = "매장아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "매장 패스워드 초기화")
    @GetMapping("/inti-storePw")
    public ResponseEntity<SaveResponse> initStorePw(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "storeId") String storeId) throws Exception {
        storeBaseInfoService.updateInitUserPw(brandId, storeId);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.INIT_PW_OK));
    }

}
