<?php
require_once __DIR__ . '/../models/Amenities.php';
require_once __DIR__ . '/../helpers/Response.php';

class AmenityController
{
    private $db;
    private $amenities;

    public function __construct($db)
    {
        $this->db = $db;
        $this->amenities = new Amenities($db);
    }

    public function index()
    {
        $stmt = $this->amenities->readAll();
        $num = $stmt->rowCount();

        if ($num > 0) {
            $amenities_arr = array();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $amenities_arr[] = $row;
            }
            Response::success("Amenities list.", $amenities_arr);
        } else {
            Response::success("No amenities found.", []);
        }
    }
}
?>