<?php

namespace App\Models;

use App\Core\Model;

class FieldTemplate extends Model
{
    protected $table = 'field_templates';
    protected $primaryKey = 'id';

    public function getUserTemplates($userId)
    {
        $stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE created_by = ? ORDER BY name ASC");
        $stmt->execute([$userId]);
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }

    public function getAllTemplates()
    {
        $stmt = $this->db->query("SELECT ft.*, u.name as created_by_name FROM {$this->table} ft LEFT JOIN users u ON ft.created_by = u.id ORDER BY ft.name ASC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }
}
