<?php
namespace App\Http\Controllers\V1\User;

use App\Http\Controllers\V1\Controller;
use App\Models\UserCollect;
use App\Models\UserConsumeRecord;
use App\Models\UserEpisodesRecord;
use App\Models\UserFavorite;
use App\Models\UserWatchRecord;
use Carbon\Carbon;
use Dingo\Api\Http\Request;
use Illuminate\Database\Eloquent\Builder;

class FavoriteController extends Controller
{

    // 检查当前短剧是否喜欢
    public function check($id)
    {
        $res = UserFavorite::filterUser()->where('episode_id',$id)->count();
        return $this->success(!empty($res));
    }

    // 添加喜欢
    public function add($id)
    {
        $res = UserFavorite::filterUser()->where('episode_id',$id)->count();
        if($res){
            return $this->success(true);
        }
        $collect = new UserFavorite();
        $collect->user_id = \user()->id;
        $collect->episode_id = $id;
        return $this->success($collect->save());
    }

    // 删除喜欢
    public function destroy($id)
    {
        $res = UserFavorite::filterUser()->where('episode_id',$id)->first();
        if(!$res){
            return $this->success(false);
        }
        return $this->success($res->delete());
    }
}
