<?php
namespace Tshen\Models;

class ClassModel
{
    protected $pdo;

    public function __construct(\PDO $pdo = null)
    {
        // use global PDO if available, otherwise keep null and return sample data
        $this->pdo = $pdo ?? ($GLOBALS['pdo'] ?? null);
    }

    public function getAllClasses(): array
    {
        if ($this->pdo instanceof \PDO) {
            $stmt = $this->pdo->query('SELECT id, name, studio_name, credits, image FROM classes');
            if ($stmt) {
                return $stmt->fetchAll(\PDO::FETCH_ASSOC);
            }
        }

        // fallback sample data so page never breaks
        return [
            ['id' => 1, 'name' => 'Yoga Flow', 'studio_name' => 'Central Yoga', 'credits' => 3, 'image' => '/public/yoga.jfif'],
            ['id' => 2, 'name' => 'HIIT Blast', 'studio_name' => 'North Fit', 'credits' => 4, 'image' => '/public/fits.avif'],
            ['id' => 3, 'name' => 'Pilates Core', 'studio_name' => 'East Studio', 'credits' => 2, 'image' => '/public/Pilates.webp'],
        ];
    }
}