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

import com.oqpo.api.service.oper.MainChartService;
import com.oqpo.api.web.dto.response.oper.mainchart.ChartResponse;
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.*;

@Slf4j
@RestController
@RequestMapping("/api/main/chart")
@Api(tags = {"메인차트 (MainChartController)"})
public class MainChartController {

    @Autowired
    private MainChartService mainChartService;

    /**
     * 설명 : 메인화면 카운트
     *
     * @param brandId
     * @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"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "메인화면 카운트")
    @GetMapping("/count")
    public ResponseEntity<ChartResponse> count(@RequestParam(value = "brandId") String brandId,
                                               @RequestParam(value = "storeId") String storeId,
                                               @RequestParam(value = "spplyId") String spplyId) throws Exception {
        return ResponseEntity.ok(mainChartService.selectMainCount(brandId, storeId, spplyId));
    }

    /**
     * 설명 : 구매요청 차트
     *
     * @param brandId
     * @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"),
            @ApiImplicitParam(name = "prType", value = "구매요청타입", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "구매요청 차트")
    @GetMapping("/pch-req-chart")
    public ResponseEntity<ChartResponse> pch_req_chart(@RequestParam(value = "brandId") String brandId,
                                                       @RequestParam(value = "storeId") String storeId,
                                                       @RequestParam(value = "prType") String prType) throws Exception {
        return ResponseEntity.ok(mainChartService.selectPchReqChart(brandId, storeId, prType));
    }

    /**
     * 설명 : 구매발주 차트
     *
     * @param brandId
     * @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"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "poType", value = "구매발주타입", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "구매발주 차트")
    @GetMapping("/pch-odr-chart")
    public ResponseEntity<ChartResponse> pch_odr_chart(@RequestParam(value = "brandId") String brandId,
                                                       @RequestParam(value = "storeId", required = false) String storeId,
                                                       @RequestParam(value = "spplyId", required = false) String spplyId,
                                                       @RequestParam(value = "poType") String poType) throws Exception {
        return ResponseEntity.ok(mainChartService.selectPchOdrChart(brandId, storeId, spplyId, poType));
    }

    /**
     * 설명 : 매출순위 차트
     *
     * @param brandId
     * @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 = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "prType", value = "구매요청타입", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "매출순위 차트")
    @GetMapping("/pr-rank-chart")
    public ResponseEntity<ChartResponse> pr_rank_chart(@RequestParam(value = "brandId") String brandId,
                                                       @RequestParam(value = "storeId", required = false) String storeId,
                                                       @RequestParam(value = "spplyId", required = false) String spplyId,
                                                       @RequestParam(value = "prType") String prType) throws Exception {
        return ResponseEntity.ok(mainChartService.selectPrRankChart(brandId, storeId, spplyId, prType));
    }

    /**
     * 설명 : 정산 차트
     *
     * @param brandId
     * @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"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "정산 차트")
    @GetMapping("/stl-chart")
    public ResponseEntity<ChartResponse> stl_chart(@RequestParam(value = "brandId") String brandId, @RequestParam(value = "storeId") String storeId,
                                                   @RequestParam(value = "spplyId") String spplyId) throws Exception {
        return ResponseEntity.ok(mainChartService.selectStlChart(brandId, storeId, spplyId));
    }

    /**
     * 설명 : 안전재고 차트
     *
     * @param brandId
     * @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("/sft-stck-chart")
    public ResponseEntity<ChartResponse> sft_stck_chart(@RequestParam(value = "brandId") String brandId,
                                                        @RequestParam(value = "storeId") String storeId) throws Exception {
        return ResponseEntity.ok(mainChartService.selectSftStckChart(brandId, storeId));
    }

    /**
     * 설명 : 입고 차트 (매장)
     *
     * @param brandId
     * @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 = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "spplyId", value = "공급사아이디", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deliType", value = "입고조회타입(당일,1주일,15일,1개월)", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "입고/출고 차트")
    @GetMapping("/deli-chart")
    public ResponseEntity<ChartResponse> deli_chart(@RequestParam(value = "brandId") String brandId,
                                                    @RequestParam(value = "storeId", required = false) String storeId,
                                                    @RequestParam(value = "spplyId", required = false) String spplyId,
                                                    @RequestParam(value = "deliType") String deliType) throws Exception {
        return ResponseEntity.ok(mainChartService.selectDeliChart(brandId, storeId, spplyId, deliType));
    }

}
