// PointsRecordController.java
package com.yami.shop.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.PointsRecord;
import com.yami.shop.bean.po.PointsRecordPo;
import com.yami.shop.bean.vo.PointsRecordVo;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.common.util.R;
import com.yami.shop.service.PointsRecordService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Arrays;

/**
 * 积分记录详细 Controller
 *
 * @author fbj
 * @since 2025-09-XX
 */
@Slf4j
@RestController
@RequestMapping("/platform/pointsRecord")
@AllArgsConstructor
public class PointsRecordController {

    private final PointsRecordService pointsRecordService;

    /**
     * 分页获取积分记录详细列表
     */
    @GetMapping("/page")
    public R<IPage<PointsRecord>> page(PageParam<PointsRecord> pageParam) {
        IPage<PointsRecord> page = pointsRecordService.page(pageParam, new QueryWrapper<PointsRecord>().orderByDesc("creationDate"));
        return R.SUCCESS(page);
    }

    /**
     * 根据ID获取积分记录详细
     */
    @GetMapping("/{id}")
    public R<PointsRecord> getById(@PathVariable Long id) {
        PointsRecord pointsRecord = pointsRecordService.getById(id);
        return R.SUCCESS(pointsRecord);
    }

    /**
     * 添加积分记录详细
     */
    @PostMapping
    public R<Void> save(@Valid @RequestBody PointsRecord pointsRecord) {
        pointsRecordService.save(pointsRecord);
        return R.SUCCESS();
    }

    /**
     * 更新积分记录详细
     */
    @PutMapping
    public R<Void> update(@Valid @RequestBody PointsRecord pointsRecord) {
        pointsRecordService.updateById(pointsRecord);
        return R.SUCCESS();
    }

    /**
     * 删除积分记录详细
     */
    @DeleteMapping
    public R<Void> delete(@RequestBody Long[] ids) {
        pointsRecordService.removeByIds(Arrays.asList(ids));
        return R.SUCCESS();
    }

    @GetMapping("/backendPointsRecordList")
    @ApiOperation("后台-积分使用记录")
    public R<IPage<PointsRecordVo>> backendOrderList(PointsRecordPo po) {
        return R.SUCCESS(pointsRecordService.backendPointsRecordList(po));
    }

    @GetMapping("/backendPointsRecordListExport")
    @ApiOperation("后台-积分使用记录-导出")
    public R<?> backendPointsRecordListExport(HttpServletResponse response, PointsRecordPo po) {
        pointsRecordService.backendPointsRecordListExport(response,po);
        return R.SUCCESS();
    }


}
