<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\RejectCoachRequest;
use App\Models\Coach;
use App\Services\Admin\CoachApprovalService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

class CoachApprovalController extends Controller
{
    public function __construct(private readonly CoachApprovalService $approvalService)
    {
    }

    public function show(Coach $coach): View
    {
        $this->authorize('view', $coach);

        $coach->load(['user', 'documents', 'goals', 'approvedBy']);

        return view('admin.coaches.show', compact('coach'));
    }

    public function approve(Coach $coach): RedirectResponse
    {
        $this->authorize('approve', $coach);

        $this->approvalService->approve($coach, auth()->user());

        return back()->with('status', 'مربی تأیید شد و اکنون در لیست عمومی نمایش داده می‌شود.');
    }

    public function reject(RejectCoachRequest $request, Coach $coach): RedirectResponse
    {
        $this->authorize('reject', $coach);

        $this->approvalService->reject($coach, $request->user(), $request->string('reason')->toString());

        return back()->with('status', 'مربی رد شد.');
    }

    public function disable(Coach $coach): RedirectResponse
    {
        $this->authorize('disable', $coach);

        $this->approvalService->disable($coach, auth()->user());

        return back()->with('status', 'حساب مربی غیرفعال شد.');
    }

    public function enable(Coach $coach): RedirectResponse
    {
        $this->authorize('enable', $coach);

        $this->approvalService->enable($coach, auth()->user());

        return back()->with('status', 'حساب مربی مجدداً فعال شد.');
    }
}
