<?php
class TipoDocumento
{
    public $id;
    public $tipoDocumento;

    public function __construct()
    {
    }

    public static function obtenerTodos(): object
    {
        $db = obtenerConexion();
        $codempresa = CODEMPRESA;

        $query = "SELECT coddocumento id,nomdocumento tipoDocumento FROM [" . DB_NET . "].dbo.gen_documento_identidad WHERE codempresa = :codempresa;";
        $stmt = $db->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);
        $stmt->bindParam(":codempresa", $codempresa, PDO::PARAM_INT);

        try {
            $stmt->execute();

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

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

    public static function obtenerTodosNET($db = null):object{
        try{
            if(empty($db)) $db = obtenerConexion();

            $query = "SELECT * FROM general.view_tiposDocumentos;";
            $stmt = $db->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);

            $stmt->execute();

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

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