<?php

namespace App\Http\Controllers;

use App\Models\FirmSize;
use function request;

class FirmSizeController extends Controller
{
    public function index()
    {
        return FirmSize::all();
    }

    public function update(FirmSize $firmSize)
    {

        $this->validateRequest();
        $firmSize->update(request()->attributes);

        return back(303)->with(['success' => 'success']);

    }

    public function validateRequest(): array
    {
        return request()->validate([
                'name_en' => 'required',
                'name_ar' => 'required',
                'sub_en' => 'required',
                'sub_ar' => 'required',
            ]

        );
    }

    public function store()
    {

        $attributes = $this->validateRequest();
        FirmSize::create($attributes);

        return back(303)->with(['success' => 'success']);

    }

    public function destroy(FirmSize $firmSize)
    {
        $firmSize->delete();
        return back(303)->with(['success' => 'success']);
    }
}
