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.RConfigRelation;
import com.ssyf.module.robot.domain.entity.RConfigRelation;
import com.ssyf.module.robot.domain.entity.RGiftConfig;
import com.ssyf.module.robot.domain.query.RConfigRelationQuery;
import com.ssyf.module.robot.domain.vo.RConfigRelationVo;
import com.ssyf.module.robot.domain.vo.RConfigRelationVo;
import com.ssyf.module.robot.domain.vo.RGiftConfigVo;
import com.ssyf.module.robot.service.RConfigRelationService;
import com.ssyf.plugs.logger.Log;
import com.ssyf.plugs.mysql.helper.PageEnhanceHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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/ConfigRelation")
public class RConfigRelationAuthController {

    @Autowired
    private RConfigRelationService baseService;

    /**
     * 新增配置关联
     */
    @Log(title = "配置关联-新增数据")
    @ApiOperation("新增配置关联")
    @PostMapping("/addOne")
    public Result<RConfigRelationVo> addOne(@Validated @RequestBody RConfigRelationQuery query) {
        if(BeanUtil.isEmpty(query)){
            return Result.fail(ApiCodeUser.PARAMETER_ERROR);
        }
        RConfigRelation entity = this.baseService.addOne(query);
        return Result.success(BeanUtil.copyProperties(entity, RConfigRelationVo.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 RConfigRelationQuery 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<RConfigRelationVo> getOneByUid(@PathVariable String uuid) {
        return Result.success(this.baseService.getOneByUid(uuid));
    }

    /**
     * 分页查询配置关联列表
     */
    @ApiOperation("分页查询配置关联列表")
    @PostMapping("/queryPage")
    public Result<IPage<RConfigRelationVo>> queryPage(@Validated @RequestBody RConfigRelationQuery query) {
        PageInfo<RConfigRelation> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp , RConfigRelationVo.class));
    }

    /**
     * 查询配置关联列表
     */
    @ApiOperation("查询配置关联列表")
    @PostMapping("/queryList")
    public Result<List<RConfigRelationVo>> queryList(@Validated @RequestBody RConfigRelationQuery query) {
        PageInfo<RConfigRelation> temp = this.baseService.getPage(query);
        return Result.success(PageEnhanceHelper.switchPageInfo(temp , RConfigRelationVo.class));
    }

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