package com.ssm.controller;

import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.PromotionProject;
import com.ssm.manage.entity.PromotionRechargeList;
import com.ssm.manage.query.PromotionListRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.PromotionRechargeListService;
import com.ssm.manage.service.SsmPromotionProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Api(value = "促销活动项目Controller",tags = {"促销活动项目相关接口"})
@RestController
@RequestMapping("/demay/ssm/promotionPro")
@Slf4j
public class SsmPromotionProjectController {
    @Autowired
    private SsmPromotionProjectService ssmPromotionProjectService;



    @Autowired
    private PromotionRechargeListService promotionRechargeListService;

    @ApiOperation(value = "查询促销活动项目  门店端-促销活动-查询促销活动项目", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/list")
    public GenericResponse list(@RequestBody PromotionListRequest promotionListRequest, HttpSession session) {
        GenericResponse pageResponse = new GenericResponse();
        if(null == promotionListRequest.getStoreId()){
            promotionListRequest.setStoreId(SessionHelp.getStoreId(session));
        }
        List<PromotionProject> list = new ArrayList<>();
        try {
            list = ssmPromotionProjectService.selectList(promotionListRequest);
        } catch (Exception e) {
            log.error("SsmPromotionProjectController.list", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setRows(list);
        return pageResponse;
    }


    @ApiOperation(value = "查询促销活动项目  门店端-促销活动-查询促销活动项目", httpMethod = "POST", response = GenericResponse.class)
    @RequestMapping("/rechargeList")
    public GenericResponse rechargeList(@RequestBody PromotionListRequest promotionListRequest, HttpSession session) {
        GenericResponse pageResponse = new GenericResponse();
        if(null == promotionListRequest.getStoreId()){
            promotionListRequest.setStoreId(SessionHelp.getStoreId(session));
        }
        List<PromotionRechargeList> list = new ArrayList<>();
        try {
            list = promotionRechargeListService.selectList(promotionListRequest);
        } catch (Exception e) {
            log.error("SsmPromotionProjectController.list", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setRows(list);
        return pageResponse;
    }
}
