package cn.ysk.cashier.controller.points;

import cn.ysk.cashier.mybatis.entity.TbPointsExchangeRecord;
import cn.ysk.cashier.mybatis.service.TbPointsExchangeRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * 积分兑换记录
 *
 * @author Tankaikai tankaikai@aliyun.com
 * @since 2.0 2024-10-25
 */
@RestController
@RequestMapping("/api/points/exchange-record")
@Api(tags = "积分兑换记录")
public class TbPointsExchangeRecordController {

    @Resource
    private TbPointsExchangeRecordService tbPointsExchangeRecordService;

    @GetMapping("page")
    @ApiOperation("分页")
    public ResponseEntity page(@RequestParam Map<String, Object> params) {
        Map<String, Object> data = tbPointsExchangeRecordService.page(params);
        return ResponseEntity.ok().body(data);
    }

    @GetMapping("{id}")
    @ApiOperation("信息")
    public ResponseEntity get(@PathVariable("id") Long id) {
        TbPointsExchangeRecord data = tbPointsExchangeRecordService.get(id);
        return ResponseEntity.ok().body(data);
    }

    @PostMapping("checkout")
    @ApiOperation("核销")
    public ResponseEntity checkout(@RequestBody TbPointsExchangeRecord record) {
        tbPointsExchangeRecordService.checkout(record.getCouponCode());
        return ResponseEntity.ok().build();
    }

    @PostMapping("cancel")
    @ApiOperation("取消")
    public ResponseEntity cancel(@RequestBody TbPointsExchangeRecord record) {
        tbPointsExchangeRecordService.cancel(record);
        return ResponseEntity.ok().build();
    }

    @PostMapping("refund")
    @ApiOperation("退单")
    public ResponseEntity refund(@RequestBody TbPointsExchangeRecord record) {
        tbPointsExchangeRecordService.refund(record);
        return ResponseEntity.ok().build();
    }

    @GetMapping("total")
    @ApiOperation("统计")
    public ResponseEntity total(@RequestParam Map<String, Object> params) {
        Map<String, Object> data = tbPointsExchangeRecordService.total(params);
        return ResponseEntity.ok().body(data);
    }
}