<?php

namespace App\Http\Controllers\Api\System;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Report;

class ReportController extends Controller
{
    // 🔹 list report (admin)
    public function index()
    {
        return Report::latest()->paginate(10);
    }

    // 🔹 create report
    public function store(Request $request)
    {
        $data = $request->validate([
            'reportable_type' => 'required',
            'reportable_id' => 'required',
            'reason' => 'required'
        ]);

        $data['reporter_id'] = auth()->id();

        return Report::create($data);
    }

    // 🔹 update status (admin)
    public function update(Request $request, $id)
    {
        $report = Report::findOrFail($id);

        $report->update($request->all());

        return $report;
    }
}