<?php

namespace App\Models;

use App\Core\Model;

class PhotoAlbum extends Model
{
    protected $table = 'photo_albums';
    protected $primaryKey = 'id';

    public function getWithPhotos()
    {
        $stmt = $this->db->query("SELECT a.*, u.name as created_by_name, (SELECT COUNT(*) FROM photos WHERE album_id = a.id) as photo_count FROM {$this->table} a LEFT JOIN users u ON a.created_by = u.id ORDER BY a.created_at DESC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }

    public function getPublic()
    {
        $stmt = $this->db->query("SELECT a.*, u.name as created_by_name, (SELECT COUNT(*) FROM photos WHERE album_id = a.id) as photo_count FROM {$this->table} a LEFT JOIN users u ON a.created_by = u.id WHERE a.is_public = 1 ORDER BY a.created_at DESC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }
}
