<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\FollowUpRequest;
use App\Services\FollowUpService;
use Illuminate\Support\Facades\Auth;

class FollowUpController extends Controller
{
    protected $followUpService;

    public function __construct(FollowUpService $followUpService)
    {
        $this->followUpService = $followUpService;
    }

    public function store(FollowUpRequest $request)
    {
        $data = $request->validated();
        $data['created_by'] = Auth::id();
        $this->followUpService->save($data);

        return redirect()->back()->withSuccess(__('messages.created', ['item' => 'Follow-Up']));
    }

    public function update(FollowUpRequest $request, $id)
    {
        $this->followUpService->update($request->validated(), $id);
        return redirect()->back()->withSuccess(__('messages.updated', ['item' => 'Follow-Up']));
    }

    public function destroy($id)
    {
        $this->followUpService->deleteById($id);
        return response()->json([
            'title' => __('messages.success'),
            'message' => __('messages.deleted', ['item' => 'Follow-Up']),
        ]);
    }
}
