<?php

namespace App\Http\Controllers\Api;

use App\Helpers\CacheHelper;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use Conner\Tagging\Model\Tag;

class UserApiController extends Controller
{
    /**
     * Get Tags (API).
     */
    public function getBlacklist(Request $request)
    {
        $user = $request->user();

        $tagWhiteList = [];
        $tagBlackList = [];

        // All Tags
        foreach (CacheHelper::getAllTags() as $tag) {
            $tagWhiteList[] = $tag->name;
        }

        // User Tags
        if ($user->tag_blacklist) {
            foreach ($user->tag_blacklist as $tag) {
                $t = Tag::where('slug', $tag)->first();
                $tagBlackList[] = $t->name;
            }
        }


        return response()->json([
            'message'   => 'success',
            'tags'      => $tagWhiteList,
            'usertags'  => $tagBlackList
        ], 200);
    }
}
