<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Story;
use App\Services\SocialService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

final class StoryInteractionController extends Controller
{
    public function __construct(private readonly SocialService $social) {}

    public function like(Request $request, int $storyId): JsonResponse
    {
        $story = Story::published()->findOrFail($storyId);

        return response()->json(
            $this->social->toggleStoryLike($request->user(), $story, $request->boolean('state', true))
        );
    }

    public function bookmark(Request $request, int $storyId): JsonResponse
    {
        $story = Story::published()->findOrFail($storyId);

        return response()->json(
            $this->social->toggleStoryBookmark($request->user(), $story, $request->boolean('state', true))
        );
    }
}