<?php

namespace App\Http\Controllers;

use App\Models\Entry;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;

class WebhookController extends Controller
{

    public function XenForoNewPost(Request $request)
    {

        if( $request->header('XF-Webhook-Secret') !== env('WEBHOOK_SECRET') )
            abort(403);

        $threadId = $request->input('data.thread_id');
        if( $threadId ){
            $entry = Entry::where('comments_thread_id', $threadId)->first();
            if( $entry ){
                Cache::forget("entry_comments_{$entry->id}");
            }
        }

        return response()->json(['success' => true]);
    }
}
