import 'package:rasadyar_chicken/data/models/poultry_export/poultry_export.dart';
import 'package:rasadyar_chicken/data/models/request/kill_registration/kill_registration.dart';
import 'package:rasadyar_chicken/data/models/response/all_poultry/all_poultry.dart';
import 'package:rasadyar_chicken/data/models/response/approved_price/approved_price.dart';
import 'package:rasadyar_chicken/data/models/response/hatching/hatching_models.dart';
import 'package:rasadyar_chicken/data/models/response/hatching_report/hatching_report.dart';
import 'package:rasadyar_chicken/data/models/response/kill_house_poultry/kill_house_poultry.dart';
import 'package:rasadyar_chicken/data/models/response/kill_request_poultry/kill_request_poultry.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_farm/poultry_farm.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_hatching/poultry_hatching.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_order/poultry_order.dart';
import 'package:rasadyar_chicken/data/models/response/poultry_science/home_poultry_science/home_poultry_science_model.dart';
import 'package:rasadyar_chicken/data/models/response/sell_for_freezing/sell_for_freezing.dart';
import 'package:rasadyar_core/core.dart';

import 'poultry_science_remote.dart';

class PoultryScienceRemoteDatasourceImp implements PoultryScienceRemoteDatasource {
  final DioRemote _httpClient;

  PoultryScienceRemoteDatasourceImp(this._httpClient);

  @override
  Future<HomePoultryScienceModel?> getHomePoultryScience({
    required String token,
    required String type,
  }) async {
    var res = await _httpClient.get(
      '/poultry_and_hatching_for_poultry_science/',
      queryParameters: {'type': type},
      headers: {'Authorization': 'Bearer $token'},
      fromJson: (json) => HomePoultryScienceModel.fromJson(json),
    );

    return res.data;
  }

  @override
  Future<PaginationModel<HatchingModel>?> getHatchingPoultry({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/poultry_and_hatching_for_poultry_science/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => PaginationModel<HatchingModel>.fromJson(
        json,
        (json) => HatchingModel.fromJson(json as Map<String, dynamic>),
      ),
    );
    return res.data;
  }

  @override
  Future<void> submitPoultryScienceReport({
    required String token,
    required FormData data,
    ProgressCallback? onSendProgress,
  }) async {
    await _httpClient.post(
      '/poultry_science_report/',
      headers: {'Authorization': 'Bearer $token'},
      data: data,
      onSendProgress: onSendProgress,
    );
  }

  @override
  Future<PaginationModel<HatchingReport>?> getPoultryScienceReport({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/poultry_science_report/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => PaginationModel<HatchingReport>.fromJson(
        json,
        (json) => HatchingReport.fromJson(json as Map<String, dynamic>),
      ),
    );
    return res.data;
  }

  @override
  Future<PaginationModel<PoultryFarm>?> getPoultryScienceFarmList({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/poultry_and_hatching_for_poultry_science/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => PaginationModel<PoultryFarm>.fromJson(
        json,
        (json) => PoultryFarm.fromJson(json as Map<String, dynamic>),
      ),
    );
    return res.data;
  }

  //region kill Registration
  @override
  Future<ApprovedPrice?> getApprovedPrice({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/approved-price/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => ApprovedPrice.fromJson(json),
    );
    return res.data;
  }

  @override
  Future<List<AllPoultry>?> getAllPoultry({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/get-all-poultry/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJsonList: (json) =>
          json.map((e) => AllPoultry.fromJson(e as Map<String, dynamic>)).toList(),
    );
    return res.data;
  }

  @override
  Future<PoultryExport?> getPoultryExport({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/poultry-export/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => PoultryExport.fromJson(json),
    );
    return res.data;
  }

  @override
  Future<SellForFreezing?> getSellForFreezing({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/sell-for-freezing/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => SellForFreezing.fromJson(json),
    );
    return res.data;
  }

  @override
  Future<List<KillRequestPoultry>?> getUserPoultry({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/Poultry/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJsonList: (json) => json.map((e) => KillRequestPoultry.fromJson(e)).toList(),
    );
    return res.data;
  }

  @override
  Future<List<PoultryHatching>?> getPoultryHatching({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/poultry_hatching/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJsonList: (json) => json.map((e) => PoultryHatching.fromJson(e)).toList(),
    );
    return res.data;
  }

  @override
  Future<List<KillHousePoultry>?> getKillHouseList({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/kill_house_list/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJsonList: (json) => json.map((e) => KillHousePoultry.fromJson(e)).toList(),
    );
    return res.data;
  }

  @override
  Future<void> submitKillRegistration({
    required String token,
    required KillRegistrationRequest request,
  }) async {
    await _httpClient.post(
      '/Poultry_Request/',
      headers: {'Authorization': 'Bearer $token'},
      data: request.toJson(),
    );
  }

  @override
  Future<PaginationModel<PoultryOrder>?> getPoultryOderList({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await _httpClient.get(
      '/Poultry_Request/',
      headers: {'Authorization': 'Bearer $token'},
      queryParameters: queryParameters,
      fromJson: (json) => PaginationModel<PoultryOrder>.fromJson(
        json,
        (data) => PoultryOrder.fromJson(data as Map<String, dynamic>),
      ),
    );

    return res.data;
  }

  @override
  Future<void> deletePoultryOder({required String token, required String orderId}) async {
    await _httpClient.delete(
      '/Poultry_Request/$orderId/',
      headers: {'Authorization': 'Bearer $token'},
    );
  }

  //endregion
}
