<?php
class TipoRol
{
    public $id;
    public $tipo;
    public $fechaRegistro;

    function __construct()
    {
        !empty($this->fechaRegistro) && $this->fechaRegistro = date("d-m-Y h:i a", strtotime($this->fechaRegistro));
    }

    public static function obtenerTodos(): object
    {
        $db = obtenerConexion();
        $query = "SELECT * FROM sistema.view_tiposRol WHERE estado = 1;";
        $stmt = $db->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);

        try {
            $stmt->execute();
            $data = $stmt->fetchAll(PDO::FETCH_CLASS, __CLASS__);

            return (object)[
                "data" => $data,
                "status" => 200,
            ];
        } catch (PDOException $e) {
            return (object)[
                "message" => $e->getMessage(),
                "status" => 500,
            ];
        }
    }
}
