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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.PointsFailureRecord;
import com.yami.shop.bean.model.PointsRecharge;
import com.yami.shop.bean.vo.PointsFailureRecordVO;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.common.util.R;
import com.yami.shop.security.platform.model.YamiSysUser;
import com.yami.shop.security.platform.util.SecurityUtils;
import com.yami.shop.service.PointsFailureRecordService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

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

/**
 * 积分充值失败记录 Controller
 *
 * @author fbj
 * @since 2025-09-XX
 */
@Slf4j
@RestController
@RequestMapping("/platform/pointsFailureRecord")
@AllArgsConstructor
public class PointsFailureRecordController {

    private final PointsFailureRecordService pointsFailureRecordService;

    /**
     * 分页获取积分充值失败记录列表
     */
    @GetMapping("/page")
    public R<IPage<PointsFailureRecord>> page(PageParam<PointsFailureRecord> pageParam) {
        IPage<PointsFailureRecord> page = pointsFailureRecordService.page(pageParam);
        return R.SUCCESS(page);
    }
    /**
     * 获取积分充值记录列表
     */
    @GetMapping("/groupByCode")
    public R<List<PointsFailureRecordVO>> groupByCode(PointsFailureRecord pointsFailureRecord) {
        List<PointsFailureRecordVO> list = pointsFailureRecordService.groupByCode(pointsFailureRecord);
        return R.SUCCESS(list);
    }

    /**
     * 根据ID获取积分充值失败记录
     */
    @GetMapping("/{id}")
    public R<PointsFailureRecord> getById(@PathVariable Long id) {
        PointsFailureRecord pointsFailureRecord = pointsFailureRecordService.getById(id);
        return R.SUCCESS(pointsFailureRecord);
    }

    /**
     * 添加积分充值失败记录
     */
    @PostMapping
    public R<Void> save(@Valid @RequestBody PointsFailureRecord pointsFailureRecord) {
        pointsFailureRecordService.save(pointsFailureRecord);
        return R.SUCCESS();
    }

    /**
     * 更新积分充值失败记录
     */
    @PutMapping
    public R<Void> update(@Valid @RequestBody PointsFailureRecord pointsFailureRecord) {
        pointsFailureRecordService.updateById(pointsFailureRecord);
        return R.SUCCESS();
    }

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


    /**
     * 根据编号导出积分充值数据
     */
    @GetMapping("/export")
    @ApiOperation(value = "导出积分充值数据", notes = "导出积分充值数据")
    public void exportPointsRecharge(HttpServletResponse response, PointsFailureRecord pointsFailureRecord) {
        pointsFailureRecordService.exportPointsRecharge(response,pointsFailureRecord);
    }
}
