package com.ssyf.module.robot.controller.auth;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.ssyf.common.web.apicode.ApiCodeUser;
import com.ssyf.common.web.result.Result;
import com.ssyf.module.robot.domain.entity.RGiftConfig;
import com.ssyf.module.robot.domain.entity.RGiftConfig;
import com.ssyf.module.robot.domain.entity.RRobotAccount;
import com.ssyf.module.robot.domain.query.RGiftConfigQuery;
import com.ssyf.module.robot.domain.vo.RGiftConfigVo;
import com.ssyf.module.robot.domain.vo.RGiftConfigVo;
import com.ssyf.module.robot.domain.vo.RRobotAccountVo;
import com.ssyf.module.robot.service.RGiftConfigService;
import com.ssyf.plugs.logger.Log;
import com.ssyf.plugs.mysql.helper.PageEnhanceHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 送礼配置开放接口
 *
 * @author: auth
 * @date: 2025-12-18
 */
@Api(tags="基础-送礼配置")
@RestController
@RequestMapping("/auth/GiftConfig")
public class RGiftConfigAuthController {

    @Autowired
    private RGiftConfigService baseService;

    /**
     * 新增送礼配置
     */
    @Log(title = "送礼配置-新增数据")
    @ApiOperation("新增送礼配置")
    @PostMapping("/addOne")
    public Result<RGiftConfigVo> addOne(@Validated @RequestBody RGiftConfigQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR);
        }
        RGiftConfig entity =this.baseService.addOne(query);
        return Result.success(BeanUtil.copyProperties(entity, RGiftConfigVo.class));
    }

    /**
     * 根据UUID删除送礼配置
     */
    @Log(title = "送礼配置-删除数据")
    @ApiOperation("根据UUID删除送礼配置")
    @PostMapping("/removeByUid/{uuid}")
    public Result removeByUid(@PathVariable String uuid) {
        this.baseService.removeByUid(uuid);
        return Result.success();
    }

    /**
     * 批量删除送礼配置
     */
    @Log(title = "送礼配置-批量删除")
    @ApiOperation("批量删除送礼配置")
    @PostMapping("/removeBatchByUids")
    public Result removeBatchByUids(@RequestBody List<String> uuids) {
        this.baseService.removeBatchByUids(uuids);
        return Result.success();
    }

    /**
     * 根据UUID更新送礼配置
     */
    @Log(title = "送礼配置-更新数据")
    @ApiOperation("根据UUID更新送礼配置")
    @PostMapping("/updateByUid")
    public Result updateByUid(@Validated @RequestBody RGiftConfigQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode() ,"更新数据不能为空");
        }
        this.baseService.updateByUid(query.getUuid() ,query);
        return Result.success();
    }

    /**
     * 根据UUID获取送礼配置
     */
    @ApiOperation("根据UUID获取送礼配置")
    @GetMapping("/getOneByUid/{uuid}")
    public Result<RGiftConfigVo> getOneByUid(@PathVariable String uuid) {
        return Result.success(this.baseService.getOneByUid(uuid));
    }

    /**
     * 分页查询送礼配置
     */
    @ApiOperation("分页查询送礼配置")
    @PostMapping("/queryPage")
    public Result<IPage<RGiftConfigVo>> queryPage(@Validated @RequestBody RGiftConfigQuery query) {
        PageInfo<RGiftConfig> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp , RGiftConfigVo.class));
    }

    /**
     * 查询送礼配置列表
     */
    @ApiOperation("查询送礼配置列表")
    @PostMapping("/queryList")
    public Result<List<RGiftConfigVo>> queryList(@Validated @RequestBody RGiftConfigQuery query) {
        PageInfo<RGiftConfig> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp , RGiftConfigVo.class));
    }

    /**
     * 统计送礼配置数量
     */
    @ApiOperation("统计送礼配置数量")
    @PostMapping("/count")
    public Result<Long> count(@Validated @RequestBody RGiftConfigQuery query) {
        Integer result = baseService.countBy(query);
        return Result.success(result);
    }
}