import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_inspection/data/data_source/remote/inspection/inspection_remote.dart';
import 'package:rasadyar_inspection/data/model/response/hatching_details/hatching_details.dart';
import 'package:rasadyar_inspection/data/model/response/poultry_location/poultry_location_model.dart';

class InspectionRemoteDataSourceImp implements InspectionRemoteDataSource {
  final DioRemote _httpClient;
  final String _BASE_URL = 'auth/api/v1/';

  InspectionRemoteDataSourceImp(this._httpClient);

  @override
  Future<Map<String, dynamic>> fetchInspectionData(String inspectionId) {
    // TODO: implement fetchInspectionData
    throw UnimplementedError();
  }

  @override
  Future<List<Map<String, dynamic>>> fetchInspections(String userId) {
    // TODO: implement fetchInspections
    throw UnimplementedError();
  }

  @override
  Future<List<PoultryLocationModel>?> getNearbyLocation({
    double? centerLat,
    double? centerLng,
    double? radius,
    String? value,
  }) async {
    DioRemote dioRemote = DioRemote(baseUrl: 'https://habackend.rasadyaar.ir/');
    await dioRemote.init();

    var res = await dioRemote.get<List<PoultryLocationModel>>(
      'poultry-loc/',
      queryParameters: buildRawQueryParams(
        centerLat: centerLat,
        centerLng: centerLng,
        radius: radius,
        value: value,
      ),
      headers: {'Content-Type': 'application/json'},
      fromJsonListAsync: (json) async =>
          parseListInIsolate(json, (json) => PoultryLocationModel.fromJson(json)),
    );

    return res.data;
  }

  @override
  Future<List<HatchingDetails>?> getHatchingDetails({String? code, bool? active}) async {
    DioRemote dioRemote = DioRemote(baseUrl: 'https://habackend.rasadyaar.ir/');
    await dioRemote.init();
    var res = await dioRemote.get(
      "get_hatching_for_bazrasi/",
      queryParameters: buildRawQueryParams(queryParams: {'code': code, 'active': active}),
      headers: {'Content-Type': 'application/json'},
      fromJsonList: (json) => json.map((e) => HatchingDetails.fromJson(e)).toList(),
    );
    return res.data;
  }
}
