<?php
declare(strict_types=1);

class CustomerModel {
    private PDO $db;

    public function __construct(PDO $db) {
        $this->db = $db;
    }

    public function getAll(): array {
        return $this->db->query("SELECT id, name, contact_person, phone, city, email, active FROM customers ORDER BY name ASC")->fetchAll();
    }

    public function getActive(): array {
        return $this->db->query("SELECT id, name, contact_person, phone, city, email FROM customers WHERE active = 1 ORDER BY id DESC")->fetchAll();
    }

    public function getById(int $id): ?array {
        $stmt = $this->db->prepare("SELECT * FROM customers WHERE id = ?");
        $stmt->execute([$id]);
        $res = $stmt->fetch();
        return $res ?: null;
    }
}
