<?php

namespace App\Http\Controllers;

use App\Enums\ReportReason;
use App\Http\Requests\StoreReportRequest;
use App\Http\Resources\ReportResource;
use App\Models\MealPosts;
use App\Models\PostReviews;
use App\Models\User;
use App\Services\ModerationReportService;
use Illuminate\Http\JsonResponse;

class ReportController extends Controller
{
    public function storeMealPost(
        StoreReportRequest $request,
        MealPosts $mealPost,
        ModerationReportService $reports,
    ): JsonResponse {
        $report = $reports->report(
            reportable: $mealPost,
            reporter: $request->user(),
            reason: ReportReason::from($request->validated('reason')),
            details: $request->validated('details'),
        );

        return (new ReportResource($report))
            ->additional(['message' => __('api.reports.created')])
            ->response()
            ->setStatusCode(201);
    }

    public function storeUser(
        StoreReportRequest $request,
        User $user,
        ModerationReportService $reports,
    ): JsonResponse {
        $report = $reports->report(
            reportable: $user,
            reporter: $request->user(),
            reason: ReportReason::from($request->validated('reason')),
            details: $request->validated('details'),
        );

        return (new ReportResource($report))
            ->additional(['message' => __('api.reports.created')])
            ->response()
            ->setStatusCode(201);
    }

    public function storePostReview(
        StoreReportRequest $request,
        PostReviews $postReview,
        ModerationReportService $reports,
    ): JsonResponse {
        $report = $reports->report(
            reportable: $postReview,
            reporter: $request->user(),
            reason: ReportReason::from($request->validated('reason')),
            details: $request->validated('details'),
        );

        return (new ReportResource($report))
            ->additional(['message' => __('api.reports.created')])
            ->response()
            ->setStatusCode(201);
    }
}
