<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\Wishlist;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class WishlistController extends Controller
{
    public function wishlist(Request $request)
    {
        if (Auth::check()) {
            $wishlist = Wishlist::where('user_id', auth()->user()->id)->where('file_id', $request->file_id)->first();
            if (isset($wishlist)) {
                $wishlist->delete();
                return ['status' => false];
            } else {
                $setNew = new Wishlist();
                $setNew->user_id = auth()->user()->id;
                $setNew->file_id = $request->file_id;
                $setNew->save();
                return ['status' => true];
            }
        } else {
            return ['auth' => false];
        }
    }
}
