<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\StoreReportRequest;
use App\Models\Report;
use Illuminate\Http\JsonResponse;

class ReportController extends Controller
{
    public function store(StoreReportRequest $request): JsonResponse
    {
        if ($request->reported_user_id === $request->user()->id) {
            return response()->json([
                'success' => false,
                'message' => 'Kamu tidak bisa melaporkan diri sendiri',
            ], 422);
        }

        Report::create([
            'reporter_id' => $request->user()->id,
            'reported_user_id' => $request->reported_user_id,
            'post_id' => $request->post_id,
            'reason' => $request->reason,
        ]);

        return response()->json([
            'success' => true,
            'message' => 'Laporan berhasil dikirim',
        ], 201);
    }
}
