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

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

import '../models/estantes_model.dart';

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

  Future<EstanteModel> fetchEstante(String token, String ides) async{
    final url = Uri.https(_url, 'PR/api/v1/quiosco/estantes/$ides');
    final res = await http.get(url,
        headers: {
          HttpHeaders.authorizationHeader : "Bearer $token"
        }
    );
    final decodedData = jsonDecode(res.body);

    if(!decodedData['response']){
      final error = EstanteModel();
      error.response = false;
      error.message = decodedData['message'];
      return error;
    }
    final estante = EstanteModel.fromJson(decodedData);
    return estante;
  }
}