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

import '../models/submodelos.dart';

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

  Future<Submodelos> fetchSubmodelos(String linea, String modelo) async{
    final modeloArr = modelo.split(" ");
    String modeloStr = "";
    int i = 0;
    do{
      modeloStr += modeloArr[i]  + "_";
      i++;
    }while(i < modeloArr.length);
    modeloStr = modeloStr.substring(0, modeloStr.length-1);

    final url = Uri.https(_url, 'PR/api/v1/obtenerSubmodelos/$linea/$modeloStr');
    final res = await http.get(url);
    final decodedData = jsonDecode(res.body);

    final submodelos = Submodelos.fromJson(decodedData);
    return submodelos;
  }
}