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

import com.ssyf.common.web.aop.RequestSynchronization;
import com.ssyf.common.web.apicode.ApiCodeUser;
import com.ssyf.common.web.result.Result;
import com.ssyf.plugs.logger.Log;
import com.ssyf.third.bmiss.model.ApiResponse;
import com.ssyf.third.bmiss.model.GiftDetail;
import com.ssyf.third.bmiss.services.GiftService;
import com.ssyf.module.robot.domain.query.RGiftServiceQuery;
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 2024-12-31
 */
@Api(tags="礼物-礼物管理")
@RestController
@RequestMapping("/auth/GiftService")
public class RGiftServiceAuthController {

    @Autowired
    private GiftService giftService;



    @Log(title = "礼物服务-赠送礼物")
    @RequestSynchronization
    @ApiOperation(value = "赠送礼物", notes = "向指定直播间赠送礼物")
    @PostMapping(value = "/sendGift")
    public Result<ApiResponse<Object>> sendGift(@RequestBody @Validated RGiftServiceQuery query) {
        
        if (query.getRoomId() == null) {
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode(), "直播间ID不能为空");
        }
        if (query.getGiftIdArr() == null || query.getGiftIdArr().isEmpty()) {
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode(), "礼物ID数组不能为空");
        }
        if (query.getToken() == null || query.getToken().trim().isEmpty()) {
            return Result.fail(ApiCodeUser.PARAMETER_ERROR.getCode(), "令牌不能为空");
        }
        
        ApiResponse<Object> response = giftService.sendGift(query.getRoomId(), query.getGiftIdArr(), query.getIsWishReach(), query.getExt(), query.getSendFrom(), query.getRecipientArr(), query.getSceneType(), query.getToken());
        return Result.success(response);
    }

    @Log(title = "礼物服务-获取礼物列表")
    @RequestSynchronization
    @ApiOperation(value = "获取礼物列表", notes = "获取礼物列表")
    @PostMapping(value = "/getGiftList")
    public Result<List<GiftDetail>> getGiftList(@RequestBody @Validated GiftDetail query) {
        List<GiftDetail> response = giftService.getGiftList(query);
        return Result.success(response);
    }

    @Log(title = "礼物服务-重置礼物缓存")
    @RequestSynchronization
    @ApiOperation(value = "重置礼物缓存", notes = "清除所有礼物相关的缓存数据")
    @PostMapping(value = "/resetCache")
    public Result resetCache() {
        giftService.resetCache();
        return Result.success();
    }

    @Log(title = "礼物服务-清空礼物缓存")
    @RequestSynchronization
    @ApiOperation(value = "清空礼物缓存", notes = "清空所有礼物缓存数据")
    @PostMapping(value = "/clearGiftCache")
    public Result clearGiftCache() {
        giftService.clearGiftCache();
        return Result.success();
    }
}