package com.ycwl.basic.controller.pc;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.biz.PriceBiz;
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
import com.ycwl.basic.model.pc.price.resp.GoodsListRespVO;
import com.ycwl.basic.service.pc.CouponService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/coupon/v1")
@Api(tags = "优惠券管理")
public class CouponController {
    @Autowired
    private CouponService couponService;
    @Autowired
    private PriceBiz priceBiz;

    @GetMapping("/{scenicId}/goodsList")
    public ApiResponse<List<GoodsListRespVO>> scenicGoodsList(@PathVariable Long scenicId) {
        List<GoodsListRespVO> data = priceBiz.listGoodsByScenic(scenicId);
        data.add(new GoodsListRespVO(-1L, "一口价"));
        return ApiResponse.success(data);
    }

    @ApiOperation("新增优惠券")
    @PostMapping("/add")
    public ApiResponse<Integer> add(@RequestBody CouponEntity coupon) {
        return ApiResponse.success(couponService.add(coupon));
    }

    @ApiOperation("更新优惠券")
    @PostMapping("/update/{id}")
    public ApiResponse<Boolean> update(@PathVariable Integer id, @RequestBody CouponEntity coupon) {
        coupon.setId(id);
        return ApiResponse.success(couponService.update(coupon));
    }

    @PutMapping("/updateStatus/{id}")
    public ApiResponse<Boolean> updateStatus(@PathVariable Integer id) {
        return ApiResponse.success(couponService.updateStatus(id));
    }

    @ApiOperation("删除优惠券")
    @DeleteMapping("/delete/{id}")
    public ApiResponse<Boolean> delete(@PathVariable Integer id) {
        return ApiResponse.success(couponService.delete(id));
    }

    @ApiOperation("根据ID查询优惠券")
    @GetMapping("/get/{id}")
    public ApiResponse<CouponEntity> getById(@PathVariable Integer id) {
        return ApiResponse.success(couponService.getById(id));
    }

    @ApiOperation("分页查询优惠券列表")
    @PostMapping("/page")
    public ApiResponse<PageInfo<CouponRespVO>> list(@RequestBody CouponQueryReq couponQuery) {
        PageHelper.startPage(couponQuery.getPageNum(), couponQuery.getPageSize());
        List<CouponRespVO> list = couponService.list(couponQuery);
        PageInfo<CouponRespVO> pageInfo = new PageInfo<>(list);
        return ApiResponse.success(pageInfo);
    }
}