package com.cyksj.web.controller.sys;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.mapper.GptMirrorDayCardGiveawayActivityMapper;
import com.cyksj.model.entity.GptMirrorDayCardGiveawayActivity;
import com.cyksj.service.mange.RefreshCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 项目名: yhlxj2
 * 文件名: SysGptMirrorDayGiveawayController
 * 创建者: JavaZou
 * 创建时间:2025/3/5 15:42
 */
@RequestMapping("/sys/mirror")
@RestController
@RequiredArgsConstructor
public class SysGptMirrorDayGiveawayController {
	private final GptMirrorDayCardGiveawayActivityMapper gptMirrorDayCardGiveawayActivityMapper;

	private final RefreshCacheService refreshCacheService;


	/**
	 * 配置参与GPT镜像天卡平台
	 */
	@PutMapping("/set/gpt/giveaway/buy/goods")
	public Result<String> setGptMirrorBuyGoods(@RequestBody GptMirrorDayCardGiveawayActivity giveawayActivity) {
		GptMirrorDayCardGiveawayActivity db = gptMirrorDayCardGiveawayActivityMapper.selectOne(Wrappers.lambdaQuery(GptMirrorDayCardGiveawayActivity.class)
				.last("limit 1"));
		if (db != null) {
			giveawayActivity.setId(db.getId());
			gptMirrorDayCardGiveawayActivityMapper.updateById(giveawayActivity);
		} else gptMirrorDayCardGiveawayActivityMapper.insert(giveawayActivity);
		refreshCacheService.refreshYhHomePageCache();
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 返回参与Gpt镜像天卡平台
	 */
	@GetMapping("/get/gpt/giveaway/buy/goods")
	public Result<GptMirrorDayCardGiveawayActivity> getGptMirrorBuyGoods() {
		GptMirrorDayCardGiveawayActivity db = gptMirrorDayCardGiveawayActivityMapper.selectOne(Wrappers.lambdaQuery(GptMirrorDayCardGiveawayActivity.class)
				.last("limit 1"));
		return GatewayResponse.SUCCESS.newBuilder().toResult(db);
	}
}
