import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;

import '../models/categorias_model.dart';

class CategoriasProvider{
  final String _url = "smart.solerpalau.mx";

  Future<CategoriaModel?> fetchCategoria(String token, String idca) async{
    final url = Uri.https(_url, 'PR/api/v1/quiosco/categorias/$idca');
    final res = await http.get(url,
        headers: {
          HttpHeaders.authorizationHeader : "Bearer $token"
        }
    );
    final decodedData = jsonDecode(res.body);
    if(decodedData['result'] != null){
      final categoria = CategoriaModel.fromJson(decodedData);
      return categoria;
    }else{
      return null;
    }
  }
}