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/poultry_science/home_poultry_science/home_poultry_science_model.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;
  }
}
