package com.czg.controller.user;

import com.czg.market.dto.MkRedemptionDTO;
import com.czg.market.service.MkRedemptionConfigService;
import com.czg.market.vo.URedemptionVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 兑换码相关
 * @author Administrator
 */
@RestController
@RequestMapping("/user/redemption")
public class URedemptionController {
    @Resource
    private MkRedemptionConfigService redemptionConfigService;

    /**
     * 使用券码
     */
    @PostMapping("/exchange")
    public CzgResult<Boolean> exchange(@Validated @RequestBody MkRedemptionDTO dto) {
        redemptionConfigService.exchange(StpKit.USER.getLoginIdAsLong(), dto);
        return CzgResult.success();
    }

    /**
     * 兑换码详细信息
     * @param code 兑换码
     */
    @GetMapping
    public CzgResult<URedemptionVO> get(@RequestParam String code) {
        return CzgResult.success(redemptionConfigService.getInfo(code));
    }


}
