package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.vo.LifeCouponVo;
import shop.alien.entity.store.vo.LifeGroupBuyMainVo;
import shop.alien.store.service.PlatformStoreCouponService;

import java.io.IOException;

@Api(tags = {"平台-套餐管理"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/platformLifeUser")
@RequiredArgsConstructor
public class PlatformStoreCouponController {

    private final PlatformStoreCouponService platformStoreCouponService;

    @ApiOperation("代金券列表")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "storeName", value = "商家名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "createdTime", value = "创建时间", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "审核状态", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型   1-代金券  2-团购（套餐）", dataType = "String", paramType = "query")
    })
    @GetMapping("/getCouponList")
    public R<IPage<LifeCouponVo>> getCouponList(Integer page, Integer size, String storeName, String status, @RequestParam(value = "createdTime", required = false) String createdTime, String phone, String type) {
        log.info("PlatformStoreCouponController.getCouponList?page={},size={},name={},status={},createdTime={},type={}", page, size, storeName, status, createdTime, type);
        return R.data(platformStoreCouponService.getCouponList(page, size, storeName, status, createdTime, phone, type));
    }

    @ApiOperation("web-新套餐列表/查询套餐状态")
    @ApiOperationSupport(order = 14)
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "storeName", value = "商家名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "createdTime", value = "创建时间", dataType = "Date", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "审核状态", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "expiredState", value = "过期状态", dataType = "String", paramType = "query")
    })
    @GetMapping("/getLifeGroupBuyMainList")
    public R<IPage<LifeGroupBuyMainVo>> getLifeGroupBuyMainList(Integer page, Integer size, String storeName, String status, @RequestParam(value = "createdTime", required = false) String createdTime, String phone, String expiredState) {
        log.info("PlatformStoreCouponController.getLifeGroupBuyMainList?page={},size={},name={},status={},createdTime={}", page, size, storeName, status, createdTime, phone, expiredState);
        return R.data(platformStoreCouponService.getLifeGroupBuyMainList(page, size, storeName, status, createdTime, phone, expiredState));
    }

    @ApiOperation("web-新套餐状态详情")
    @ApiOperationSupport(order = 16)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/getLifeGroupBuyMainByDetail")
    public R<LifeGroupBuyMainVo> getLifeGroupBuyMainByDetail(Integer id) {
        log.info("PlatformStoreCouponController.getLifeGroupBuyMainByDetail?id={}", id);
        return R.data(platformStoreCouponService.getLifeGroupBuyMainByDetail(id));
    }

    /**
     * web-分页查询店铺信息
     *
     * @param pageNum      页码
     * @param pageSize     页容
     * @param status       审核状态
     * @param expiredState 过期状态
     * @return IPage<StoreInfoVo>
     */
    @ApiOperation("web-分页查询代金券状态")
    @ApiOperationSupport(order = 7)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "审核状态", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "expiredState", value = "过期状态", dataType = "String", paramType = "query"),
    })
    @GetMapping("/getCouponStatusList")
    public R<IPage<LifeCouponVo>> getStoresPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String expiredState) {
        log.info("PlatformStoreCouponController.getCouponStatusList?pageNum={},pageSize={},status={},expiredState={}",
                pageNum, pageSize, status, expiredState);
        return R.data(platformStoreCouponService.getCouponStatusList(pageNum, pageSize, status, expiredState));
    }

    @ApiOperation("web-导出套餐状态Excel")
    @ApiOperationSupport(order = 11)
    @GetMapping("/couponStatusExport")
    public R couponStatusExport(@RequestParam(required = false) String status,
                                @RequestParam(required = false) String expiredState) throws IOException {
        log.info("PlatformStoreCouponController.couponStatusExport");
        return R.data(platformStoreCouponService.couponStatusExport(status, expiredState));
    }

    @ApiOperation("web-新导出套餐状态Excel")
    @ApiOperationSupport(order = 15)
    @GetMapping("/lifeGroupBuyMainStatusExport")
    public R lifeGroupBuyMainStatusExport(@RequestParam(required = false) String status,
                                @RequestParam(required = false) String expiredState) throws IOException {
        log.info("PlatformStoreCouponController.lifeGroupBuyMainStatusExport");
        return R.data(platformStoreCouponService.lifeGroupBuyMainStatusExport(status, expiredState));
    }

    @ApiOperation("web-套餐状态删除")
    @ApiOperationSupport(order = 11)
    @GetMapping("/deleteCouponStatus")
    public int deleteCouponStatus(@RequestParam("id") Integer id) {
        log.info("PlatformStoreCouponController.deleteCouponStatus");
        return platformStoreCouponService.deleteCouponStatus(id);
    }

    @ApiOperation("代金券详情")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true)})
    @GetMapping("/getCouponById")
    public R<LifeCouponVo> getCouponById(Integer id) {
        log.info("PlatformStoreCouponController.getCouponById?id={}", id);
        return R.data(platformStoreCouponService.getCouponById(id));
    }

    @ApiOperation("web-套餐/代金券审核")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "comment", value = "审批意见", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "代金券/套餐类型 1:代金券 2:套餐", dataType = "String", paramType = "query")})
    @GetMapping("/approvalCoupon")
    public R<Integer> approvalCoupon(Integer id, Integer status, String comment, String type) {
        log.info("PlatformStoreCouponController.approvalCoupon?id={},status={},comment={}type={}", id, status, comment, type);
        return R.data(platformStoreCouponService.approvalCoupon(id, status, comment, type));
    }

}
