package com.kym.miniapp.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kym.service.WashOrderService;
import com.kym.service.cache.KymCache;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 停车优惠链接跳转
 * @author skyline
 * @since 2024-08-07
 */
@RestController
@RequestMapping("/parking-coupon")
public class ParkingCouponController {

	private final WashOrderService washOrderService;

    public ParkingCouponController(WashOrderService washOrderService) {
        this.washOrderService = washOrderService;
    }

    /**
	 * 停车优惠链接跳转
	 */
    @SaIgnore
	@GetMapping
	public void jump(HttpServletResponse response, @RequestParam String code) throws IOException {
		// 从缓存中获取链接并跳转
		var url = KymCache.INSTANCE.getParkingCouponUrl(code);
		response.sendRedirect(url);
	}

	/**
	 * 查询是否符合停车优惠
	 */
    @SaIgnore
	@GetMapping("/checkParkingCoupon")
	public String checkParkingCoupon(@RequestParam String mobilePhone) {
		return washOrderService.checkParkingCoupon(mobilePhone);
	}

}
