import 'dart:convert';

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

import '../models/aviso.dart';
import '../models/avisos.dart';
class AvisosProvider{
  final _url = 'smart.solerpalau.mx';

  Future<Avisos> fetchAvisos(String token, String dinum) async{
    final url = Uri.https(_url, 'PR/api/v1/quiosco/obtenerAvisos');
    final res = await http.post(url,
        headers: {
          'Authorization' : 'Bearer $token'
        },
        body: {
          'DINUM' : dinum
        }
    );
    final decodedData = jsonDecode(res.body);
    final avisos = Avisos.fromJson(decodedData);
    return avisos;
  }

  Future<Aviso> verAviso(String token, String idRegistroEnviar, String idUsuario, String estatus, String ip) async{
    final url = Uri.https(_url, 'PR/api/v1/quiosco/leerAviso');
    print(idRegistroEnviar);
    final res = await http.post(url,
        headers: {
          'Authorization' : 'Bearer $token'
        },
        body: {
          'tipoArchivo' : 'PDF',
          'idRegistroEnviar' : idRegistroEnviar,
          'idUsuario' : idUsuario,
          'estatus' : estatus,
          'IP' : ip
        }
    );
    print(token);
    final decodedData = jsonDecode(res.body);
    if(decodedData['result'].isEmpty){
      return Aviso();
    }
    final aviso = Aviso.fromJson(decodedData);
    return aviso;
  }
}