import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/data/services/network_status.dart';
import 'package:rasadyar_livestock/data/data_source/local/tmp/tmp_local_data-source.dart';
import 'package:rasadyar_livestock/data/data_source/remote/livestock/livestock_remote.dart';
import 'package:rasadyar_livestock/data/model/local/location/tmp_locations.dart';
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
import 'package:rasadyar_livestock/data/model/response/live_tmp/livestock_model.dart';

import 'livestock_repository.dart';

class LivestockRepositoryImp implements LivestockRepository {
  final LivestockRemoteDataSource livestockRemote;
  final TmpLocalDataSource tmpLocalDataSource;

  LivestockRepositoryImp({required this.livestockRemote,required this.tmpLocalDataSource});

  @override
  Future<LocationDetails?> getLocationDetails({
    required double latitude,
    required double longitude,
  }) async {
    return await livestockRemote.getLocationDetailsByLatLng(
      latitude: latitude,
      longitude: longitude,
    );
  }

  @override
  Future<bool> createTaggingLiveStock({required LivestockData data}) async {
    return await livestockRemote.createTaggingLiveStock(data: data);
  }

  @override
  Future<List<LatLng>> getLocations() async {
    if (NetworkStatus().isConnected.value) {
      return [
        LatLng(35.824891, 50.948025),
        LatLng(35.825000, 50.949000),
        LatLng(35.823000, 50.947000),
        LatLng(35.826000, 50.950000),
        LatLng(35.827000, 50.951000),
        LatLng(35.828000, 50.952000),
        LatLng(35.829000, 50.953000),
        LatLng(35.830000, 50.954000),
        LatLng(35.831000, 50.955000),
        LatLng(35.832000, 50.956000),
        LatLng(35.832000, 50.956055),
      ];
    } else {
      var res = await tmpLocalDataSource.getLocations();

      return res.map((e) => LatLng(e.lat ?? 0.0, e.long ?? 0.0)).toList();
    }
  }

  @override
  Future<void> addLocations(List<LatLng> latList) async {
    await tmpLocalDataSource.addLocations(
      latList.map((e) => TmpLocations(lat: e.latitude, long: e.longitude)).toList(),
    );
    iLog("it is done");
  }
}
