<?php

namespace App\Http\Controllers;

use App\Http\Requests\CreateCategoryRequest;
use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    public function index()
    {
        $categories = Category::select('id', 'name', 'is_active')->orderBy('name', 'asc')->get();
        
        return response()->json([
            'message' => 'Categorias obtidas com sucesso',
            'data' => $categories,
            'errors' => null,
        ], 200); 
    }

    public function create(CreateCategoryRequest $request)
    {
        $category = Category::create($request->validated());
        return response()->json([
            'message' => 'Categoria criada com sucesso',
            'data' => $category,
            'errors' => null,
        ], 201);
    }
}
