<?php

namespace App\Http\Services\V1;

use App\Generated\V1\Messages\Signin\Reward72PairCouponMessage;
use App\Generated\V1\Messages\Signin\Reward72DiscountCouponMessage;
use App\Generated\V1\Messages\Signin\RewardSupVipCouponMessage;
use App\Generated\V1\Messages\Signin\RewardUnLookCardMessage;
use App\Generated\V1\Messages\Signin\RewardPopularityMessage;
use App\Generated\V1\Messages\Signin\RewardFlowerMessage;
use App\Generated\V1\Messages\Signin\SignMessage;
use App\Generated\V1\Messages\Signin\TodayMessage;
use App\Http\Controllers\Core\Auth;
use App\Services\User\SignService;

class SignInService
{


    public function __construct(SignService $signInManager)
    {
        $this->signInManager = $signInManager;
    }


    public function today(TodayMessage $message)
    {
        $uid = Auth::auth();
        $data = $this->signInManager->today($uid);
        $message->setResponse($data);
    }

    /**
     * 签到
     * @param  SignMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function sign(SignMessage $message)
    {
        $uid = Auth::auth();
        $platform = $message->getRequest()->header('platform');
        $this->signInManager->sign($uid, $platform);
    }

    /**
     * 领取小花奖励
     * @param  RewardFlowerMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function rewardFlower(RewardFlowerMessage $message)
    {
        $uid = Auth::auth();
        $flower = $this->signInManager->rewardFlower($uid);
        $message->setResponse([
            'flower' => $flower
        ]);
    }

    /**
     * 领取人气值奖励
     * @param  RewardPopularityMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function rewardPopularity(RewardPopularityMessage $message)
    {
        $uid = Auth::auth();
        $popularity = $this->signInManager->rewardPopularity($uid);
        $message->setResponse([
            'popularity' => $popularity
        ]);
    }

    /**
     * 领取解锁次数
     * @param  RewardUnLookCardMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function rewardUnLookCard(RewardUnLookCardMessage $message)
    {
        $uid = Auth::auth();
        $this->signInManager->rewardUnLookCard($uid);
    }

    /**
     * 领取72h卡券满减券
     * @param  RewardSupVipCouponMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function rewardSupVipCoupon(RewardSupVipCouponMessage $message)
    {
        $uid = Auth::auth();
        $this->signInManager->rewardCouponSuperVip($uid);
    }

    /**
     * 72小时折扣券
     * @param  Reward72DiscountCouponMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function reward72DiscountCoupon(Reward72DiscountCouponMessage $message)
    {
        $uid = Auth::auth();
        $this->signInManager->rewardCoupon72Dis($uid);
    }

    /**
     * 72小时入场券
     * @param  Reward72PairCouponMessage  $message
     * @throws \App\Exceptions\AlertException
     * @throws \Tymon\JWTAuth\Exceptions\JWTException
     */
    public function reward72PairCoupon(Reward72PairCouponMessage $message)
    {
        $uid = Auth::auth();
        $this->signInManager->rewardCoupon72Pair($uid);
    }
}
