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

import '../utils/const.dart';

class CatService {
  static Future<List<dynamic>?> loadCats(double lat1, double lon1, double lat2,
      double lon2, double lat3, double lon3, double lat4, double lon4) async {
    List<dynamic> cats = [];
    String serverUrl = ConstValues.currentServer();
    String url =
        '$serverUrl/api/cats/?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4';
    //print('++++++++$url');
    final response = await http.get(
      Uri.parse(url),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
    );

    if (response.statusCode == 200) {
      cats = json.decode(utf8.decode(response.bodyBytes));
    }
    return cats;
  }

  static Future<List<dynamic>?> loadCatByCity(String cityname) async {
    List<dynamic> cats = [];
    String serverUrl = ConstValues.currentServer();
    String url = '$serverUrl/api/catbycity/?$cityname';
    //print('++++++++$url');
    final response = await http.get(
      Uri.parse(url),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
    );

    if (response.statusCode == 200) {
      cats = json.decode(utf8.decode(response.bodyBytes));
    }
    return cats;
  }
}
