<?php

namespace Modules\Supplier\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Supplier\Requests\Admin\SupplierRequest;
use Modules\Supplier\Services\SupplierService;

class SupplierController extends Controller
{
    private string $viewDirectory = 'admin.suppliers.';

    public function __construct(private SupplierService $supplierService)
    {
    }

    public function index(Request $request): View
    {
        $head = __('suppliers.head');
        $action = route('suppliers.store');
        $suppliers = $this->supplierService->get();

        return view($this->viewDirectory . 'index', get_defined_vars());
    }

    public function store(SupplierRequest $request): JsonResponse
    {
        $this->supplierService->create($request->validated());
        session()->flash('message', __('dashboard.saveDone'));

        return ResponseService::response([
            'status' => 200,
            'message' => __('web.success'),
            'data' => route('suppliers.index'),
        ]);
    }
}
