<?php
declare(strict_types=1);

require_once __DIR__ . '/../config/database.php';

class TutorialVideo
{
    public function latest(int $limit = 30): array
    {
        $stmt = db()->prepare('SELECT * FROM tutorial_videos WHERE status = :status ORDER BY id DESC LIMIT :lim');
        $stmt->bindValue(':status', 'published');
        $stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
        $stmt->execute();
        return $stmt->fetchAll();
    }

    public function all(int $limit = 200): array
    {
        $stmt = db()->prepare('SELECT * FROM tutorial_videos ORDER BY id DESC LIMIT :lim');
        $stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
        $stmt->execute();
        return $stmt->fetchAll();
    }

    public function create(array $data): bool
    {
        $stmt = db()->prepare('INSERT INTO tutorial_videos (title,description,video_url,thumbnail_url,status) VALUES (:title,:description,:video_url,:thumbnail_url,:status)');
        return $stmt->execute($data);
    }
}
