<?php
namespace App\Models;

use App\Core\Database;

class Organization
{
    public function all()
    {
        $db = Database::getInstance();
        return $db->query("SELECT * FROM organizations ORDER BY id DESC")->fetchAll();
    }

    public function find($id)
    {
        $db = Database::getInstance();
        $stmt = $db->prepare("SELECT * FROM organizations WHERE id = ?");
        $stmt->execute([$id]);
        return $stmt->fetch();
    }

    public function create($data)
    {
        $db = Database::getInstance();
        $stmt = $db->prepare("INSERT INTO organizations (name, code) VALUES (?, ?)");
        return $stmt->execute([$data['name'], $data['code']]);
    }
}
