<?php

namespace App\Models;

use App\Core\Model;

class CustomLink extends Model
{
    protected $table = 'custom_links';
    protected $primaryKey = 'id';

    public function getActive()
    {
        $stmt = $this->db->query("SELECT * FROM {$this->table} WHERE is_active = 1 ORDER BY sort_order ASC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }

    public function getByCategory($category)
    {
        $stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE is_active = 1 AND category = ? ORDER BY sort_order ASC");
        $stmt->execute([$category]);
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }

    public function getCategories()
    {
        $stmt = $this->db->query("SELECT DISTINCT category FROM {$this->table} WHERE is_active = 1 AND category IS NOT NULL ORDER BY category ASC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }
}
