<?php

namespace App\Controllers\Api;

use CodeIgniter\RESTful\ResourceController;
use App\Models\ProductModel;

class ProductApi extends ResourceController
{
    public function index()
    {
        $model = new ProductModel();
        // Implementasi pagination agar API tidak berat
        $data = $model->paginate(20);
        return $this->respond($data);
    }

    public function show($id = null)
    {
        $model = new ProductModel();
        $data = $model->find($id);
        
        if (!$data) return $this->failNotFound('Produk tidak ditemukan');
        
        return $this->respond($data);
    }
}