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

import '../models/login_model.dart';

class LoginProvider{
  final String _url = "smart.solerpalau.mx";
  final LoginVentilacionModel _loginModel = LoginVentilacionModel(
      result: Result(
          accessToken: "",
          idUsuario: "",
          nombre: "",
          verificacion: "",
          correo: "",
          movil: "",
          pais: "",
          estado: "",
          ciudad: ""
      ),
      response: false,
      message: ""
  );

  Future<LoginVentilacionModel> fetchLogin(String correo, String contra) async{
    final url = Uri.https(_url, 'PR/api/v1/matrizMemoriasCalculo/loginVentilacion');
    final res = await http.post(url,
        body: {
          "CORREO": correo,
          "CONTRA": contra
        }
    );

    final dec = jsonDecode(res.body);

    if(!dec['response']){
      _loginModel.message = dec['message'];
      return _loginModel;
    }else{
      final loginModel = LoginVentilacionModel.fromJson(dec);
      return loginModel;
    }
  }
}