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

import com.oqpo.api.service.salesmng.SalesMngService;
import com.oqpo.api.web.dto.request.salesmng.ItemSalesGridRequest;
import com.oqpo.api.web.dto.request.salesmng.StoreSalesGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/sale/mng")
@Api(tags = {"매출관리 (SaleMngController)"})
public class SalesMngController {

    @Autowired
    private SalesMngService salesMngService;

    /**
     * 설명 : 매장별 매출현황 그리드 리스트
     *
     * @param storeSalesGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "매장별 매출현황 그리드 리스트")
    @PostMapping("/store-grid-list")
    public ResponseEntity<GridResponse> storeGridList(@RequestBody @Valid StoreSalesGridRequest storeSalesGridRequest) throws Exception {
        return ResponseEntity.ok(salesMngService.selectStoreSalesGridList(storeSalesGridRequest.getSBrandId(), storeSalesGridRequest.getSStoreId(),
                storeSalesGridRequest.getFromDt(), storeSalesGridRequest.getToDt(), storeSalesGridRequest.toDTO(storeSalesGridRequest)));
    }

    /**
     * 설명 : 품목별 매출현황 그리드 리스트
     *
     * @param itemSalesGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "품별별 매출현황 그리드 리스트")
    @PostMapping("/item-grid-list")
    public ResponseEntity<GridResponse> itemGridList(@RequestBody @Valid ItemSalesGridRequest itemSalesGridRequest) throws Exception {
        return ResponseEntity.ok(salesMngService.selectItemSalesGridList(itemSalesGridRequest.getSBrandId(), itemSalesGridRequest.getSStoreId(),
                itemSalesGridRequest.getSItemNm(), itemSalesGridRequest.getFromDt(), itemSalesGridRequest.getToDt(), itemSalesGridRequest.toDTO(itemSalesGridRequest)));
    }

}
