<?php

namespace App\Models;

use App\Core\Model;

class PostCategory extends Model
{
    protected $table = 'post_categories';
    protected $primaryKey = 'id';

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

    public function findBySlug($slug)
    {
        $stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE slug = ? LIMIT 1");
        $stmt->execute([$slug]);
        return $stmt->fetch(\PDO::FETCH_OBJ);
    }

    public function getPostCount($id)
    {
        $stmt = $this->db->prepare("SELECT COUNT(*) as count FROM announcements WHERE category_id = ?");
        $stmt->execute([$id]);
        return $stmt->fetch(\PDO::FETCH_OBJ)->count;
    }
}
