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

import '../db/db_querys.dart';

class ApiDataPost{
  Future sincronizacao(urlAPI,mode,nameCityApi,map)async{
    // http://192.168.0.42:8010/api/atb/desenvolvimento/corumbatai/sincronizacao
    // print('sinc');
    // print(map);
    final url = '${urlAPI}${mode}/${nameCityApi}/sincronizacao';
    print(url);
    var response = await http.post(
      Uri.parse(url),
      body: jsonEncode(map),
    );
    print(response.body);
    print(response.statusCode);
    if(response.statusCode == 200) {
      await DBQuerys().updateCidadao();
      await DBQuerys().updateCadastroIndividuais();
      await DBQuerys().updateCadastroDomiciliar();
      await DBQuerys().updateATENDIMENTOS_DOMICILIARES();
      await DBQuerys().deleteATENDS_DOM_COMPL();
      await DBQuerys().deleteATENDS_DOM_PROC();
      await DBQuerys().updateVISITAS_DOMICILIARES();
      await DBQuerys().deleteVISITAS_DOMICILIARES_COMPL();
      await DBQuerys().deleteVISITAS_DOMICILIARES_PROC();
      return json.decode(response.body);
    }else{
      return 'error';
    }
  }
}