<?php

class Type {

    private $Id_type;
    private $libelle;



    public function __construct($Id_type, $libelle) {
        $this->Id_type = $Id_type;
        $this->libelle = $libelle;
    }



    public static function getTypeById($id_type) {
        $db = Bdd::getInstance();
        $pdo = $db->getConnection();  
        try {
            $stmt = $pdo->prepare("SELECT * FROM type WHERE Id_type = :id_type");
            $stmt->bindParam(':id_type', $id_type);
            $stmt->execute();

            if ($stmt->rowCount() == 1) {
                $row = $stmt->fetch(PDO::FETCH_ASSOC);
                return new Type(
                    $row['Id_type'],
                    $row['libelle']
                );
            } else {
                return null; // Type non trouvé
            }
        } catch (PDOException $e) {
            echo "Erreur: " . $e->getMessage();
        }
    }


    public function getId_type() {
        return $this->Id_type;
    }

    public function setId_type($Id_type) {
        $this->Id_type = $Id_type;
    }

    public function getLibelle() {
        return $this->libelle;
    }

    public function setLibelle($libelle) {
        $this->libelle = $libelle;
    }
}
