package com.cyksj.web.controller.group;

import com.cyksj.common.constant.Constant;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.service.ticket.UserReceiveTrialTicketRecordService;
import com.cyksj.web.util.StpUserUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目名: yhlxj
 * 文件名: MidJourneyGuideController
 * 创建者: JavaZou
 * 创建时间:2024/6/3 17:46
 */
@Slf4j
@RequestMapping("/applets/mj")
@RestController
@RequiredArgsConstructor
public class MidJourneyGuideController {
	private final UserReceiveTrialTicketRecordService userReceiveTrialTicketRecordService;

	/**
	 * 领取mj试用车票
	 */
	@PostMapping("/receive/trial")
	public Result<String> receiveTrialTicket() {
		long userId = StpUserUtil.getLoginIdAsLong();
		userReceiveTrialTicketRecordService.sendTicketAndRecord(userId, Constant.MIDJOURNEY_TRIAL_SKU_ID);
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}

	/**
	 * 是否已领取mj试用车票
	 */
	@GetMapping("/hasReceived")
	public Result<Boolean> isReceiveTrialTicket() {
		long userId = StpUserUtil.getLoginIdAsLong();
		Boolean flag = userReceiveTrialTicketRecordService.isReceiveTrialTicket(userId, Constant.MIDJOURNEY_TRIAL_SKU_ID);
		return GatewayResponse.SUCCESS.newBuilder().toResult(flag);
	}
}
