<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\item_Categories;

class itemCategoriesController extends Controller
{
    public function store(Request $request)
    {
        $request->validate([
            'Category_name' => 'required',
           
        ]);

        $itemCategories = new item_Categories;
        $itemCategories->Category_name = $request->Category_name;
        $itemCategories->save();

        return response()->json(['message' => 'Item Category created successfully'], 201);
    }

    public function index()
    {
        $itemCategories = item_Categories::all();
        return response()->json($itemCategories);
    }

    public function update(Request $request, $id)
    {
        $request->validate([
            'Category_name' => 'required',
        ]);

        $itemCategories = item_Categories::find($id);
        $itemCategories->Category_name = $request->Category_name;
        $itemCategories->save();

        return response()->json(['message' => 'Item Category updated successfully'], 200);
    }
}
