import 'package:rasadyar_chicken/data/data_source/local/chicken_local.dart';
import 'package:rasadyar_chicken/data/data_source/remote/chicken/chicken_remote.dart';
import 'package:rasadyar_chicken/data/models/local/widely_used_local_model.dart';
import 'package:rasadyar_chicken/data/models/request/change_password/change_password_request_model.dart';
import 'package:rasadyar_chicken/data/models/request/conform_allocation/conform_allocation.dart';
import 'package:rasadyar_chicken/data/models/request/create_steward_free_bar/create_steward_free_bar.dart';
import 'package:rasadyar_chicken/data/models/request/steward_free_sale_bar/steward_free_sale_bar_request.dart';
import 'package:rasadyar_chicken/data/models/request/submit_steward_allocation/submit_steward_allocation.dart';
import 'package:rasadyar_chicken/data/models/response/allocated_made/allocated_made.dart';
import 'package:rasadyar_chicken/data/models/response/bar_information/bar_information.dart';
import 'package:rasadyar_chicken/data/models/response/broadcast_price/broadcast_price.dart';
import 'package:rasadyar_chicken/data/models/response/dashboard_kill_house_free_bar/dashboard_kill_house_free_bar.dart';
import 'package:rasadyar_chicken/data/models/response/guild/guild_model.dart';
import 'package:rasadyar_chicken/data/models/response/guild_profile/guild_profile.dart';
import 'package:rasadyar_chicken/data/models/response/imported_loads_model/imported_loads_model.dart';
import 'package:rasadyar_chicken/data/models/response/inventory/inventory_model.dart';
import 'package:rasadyar_chicken/data/models/response/iran_province_city/iran_province_city_model.dart';
import 'package:rasadyar_chicken/data/models/response/kill_house_distribution_info/kill_house_distribution_info.dart';
import 'package:rasadyar_chicken/data/models/response/out_province_carcasses_buyer/out_province_carcasses_buyer.dart';
import 'package:rasadyar_chicken/data/models/response/roles_products/roles_products.dart';
import 'package:rasadyar_chicken/data/models/response/segmentation_model/segmentation_model.dart';
import 'package:rasadyar_chicken/data/models/response/steward_free_bar/steward_free_bar.dart';
import 'package:rasadyar_chicken/data/models/response/steward_free_bar_dashboard/steward_free_bar_dashboard.dart';
import 'package:rasadyar_chicken/data/models/response/steward_free_sale_bar/steward_free_sale_bar.dart';
import 'package:rasadyar_chicken/data/models/response/steward_sales_info_dashboard/steward_sales_info_dashboard.dart';
import 'package:rasadyar_chicken/data/models/response/user_profile/user_profile.dart';
import 'package:rasadyar_chicken/data/models/response/waiting_arrival/waiting_arrival.dart'
    hide ProductModel;
import 'package:rasadyar_core/core.dart';

import 'chicken_repository.dart';

class ChickenRepositoryImp implements ChickenRepository {
  final ChickenRemoteDatasource remote;
  final ChickenLocalDataSource local;

  ChickenRepositoryImp({required this.remote, required this.local});

  //region Remote
  @override
  Future<List<InventoryModel>?> getInventory({
    required String token,
    CancelToken? cancelToken,
  }) async {
    var res = await remote.getInventory(token: token, cancelToken: cancelToken);
    return res;
  }

  @override
  Future<KillHouseDistributionInfo?> getKillHouseDistributionInfo({required String token}) async {
    var res = await remote.getKillHouseDistributionInfo(token: token);
    return res;
  }

  @override
  Future<BarInformation?> getGeneralBarInformation({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getGeneralBarInformation(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<PaginationModel<WaitingArrivalModel>?> getWaitingArrivals({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getWaitingArrivals(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<void> setSateForArrivals({
    required String token,
    required Map<String, dynamic> request,
  }) async {
    await remote.setSateForArrivals(token: token, request: request);
  }

  @override
  Future<PaginationModel<ImportedLoadsModel>?> getImportedLoadsModel({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getImportedLoadsModel(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<PaginationModel<AllocatedMadeModel>?> getAllocatedMade({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getAllocatedMade(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<void> confirmAllocation({
    required String token,
    required Map<String, dynamic> allocation,
  }) async {
    await remote.confirmAllocation(token: token, allocation: allocation);
  }

  @override
  Future<void> denyAllocation({required String token, required String allocationToken}) async {
    await remote.denyAllocation(token: token, allocationToken: allocationToken);
  }

  @override
  Future<void> confirmAllAllocation({
    required String token,
    required List<String> allocationTokens,
  }) async {
    await remote.confirmAllAllocation(token: token, allocationTokens: allocationTokens);
  }

  @override
  Future<List<ProductModel>?> getRolesProducts({required String token}) async {
    var res = await remote.getRolesProducts(token: token);
    return res;
  }

  @override
  Future<List<GuildModel>?> getGuilds({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getGuilds(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<GuildProfile?> getProfile({required String token}) async {
    var res = await remote.getProfile(token: token);
    return res;
  }

  @override
  Future<void> postSubmitStewardAllocation({
    required String token,
    required SubmitStewardAllocation request,
  }) async {
    await remote.postSubmitStewardAllocation(token: token, request: request);
  }

  @override
  Future<void> deleteStewardAllocation({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    await remote.deleteStewardAllocation(token: token, queryParameters: queryParameters);
  }

  @override
  Future<void> updateStewardAllocation({
    required String token,
    required ConformAllocation request,
  }) async {
    await remote.updateStewardAllocation(token: token, request: request);
  }

  @override
  Future<StewardFreeBarDashboard?> getStewardDashboard({
    required String token,
    required String stratDate,
    required String endDate,
  }) async {
    var res = await remote.getStewardDashboard(
      token: token,
      stratDate: stratDate,
      endDate: endDate,
    );
    return res;
  }

  @override
  Future<DashboardKillHouseFreeBar?> getDashboardKillHouseFreeBar({
    required String token,
    required String stratDate,
    required String endDate,
  }) async {
    var res = await remote.getDashboardKillHouseFreeBar(
      token: token,
      stratDate: stratDate,
      endDate: endDate,
    );
    return res;
  }

  @override
  Future<PaginationModel<StewardFreeBar>?> getStewardPurchasesOutSideOfTheProvince({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getStewardPurchasesOutSideOfTheProvince(
      token: token,
      queryParameters: queryParameters,
    );
    return res;
  }

  @override
  Future<List<IranProvinceCityModel>?> getCity({required String provinceName}) async {
    var res = await remote.getCity(provinceName: provinceName);
    return res;
  }

  @override
  Future<List<IranProvinceCityModel>?> getProvince({CancelToken? cancelToken}) async {
    var res = await remote.getProvince(cancelToken: cancelToken);
    return res;
  }

  @override
  Future<void> createStewardPurchasesOutSideOfTheProvince({
    required String token,
    required CreateStewardFreeBar body,
  }) async {
    await remote.createStewardPurchasesOutSideOfTheProvince(token: token, body: body);
  }

  @override
  Future<CreateStewardFreeBar?> editStewardPurchasesOutSideOfTheProvince({
    required String token,
    required CreateStewardFreeBar body,
  }) async {
    return await remote.editStewardPurchasesOutSideOfTheProvince(
      token: token,
      queryParameters: body.toJson()..removeWhere((key, value) => value == null),
    );
  }

  @override
  Future<void> deleteStewardPurchasesOutSideOfTheProvince({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    await remote.deleteStewardPurchasesOutSideOfTheProvince(
      token: token,
      queryParameters: queryParameters,
    );
  }

  @override
  Future<PaginationModel<OutProvinceCarcassesBuyer>?> getOutProvinceCarcassesBuyer({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getOutProvinceCarcassesBuyer(
      token: token,
      queryParameters: queryParameters,
    );
    return res;
  }

  @override
  Future<void> createOutProvinceCarcassesBuyer({
    required String token,
    required OutProvinceCarcassesBuyer body,
  }) async {
    await remote.createOutProvinceCarcassesBuyer(token: token, body: body);
  }

  @override
  Future<PaginationModel<StewardFreeSaleBar>?> getStewardFreeSaleBar({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getStewardFreeSaleBar(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<void> createOutProvinceStewardFreeBar({
    required String token,
    required StewardFreeSaleBarRequest body,
  }) async {
    await remote.createOutProvinceStewardFreeBar(token: token, body: body);
  }

  @override
  Future<void> updateOutProvinceStewardFreeBar({
    required String token,
    required StewardFreeSaleBarRequest body,
  }) async {
    await remote.updateOutProvinceStewardFreeBar(token: token, body: body);
  }

  @override
  Future<void> deleteOutProvinceStewardFreeBar({required String token, required String key}) async {
    await remote.deleteOutProvinceStewardFreeBar(token: token, key: key);
  }

  @override
  Future<UserProfile?> getUserProfile({required String token}) async {
    var res = await remote.getUserProfile(token: token);
    return res;
  }

  @override
  Future<void> updateUserProfile({required String token, required UserProfile userProfile}) async {
    await remote.updateUserProfile(token: token, userProfile: userProfile);
  }

  @override
  Future<void> updatePassword({
    required String token,
    required ChangePasswordRequestModel model,
  }) async {
    await remote.updatePassword(token: token, model: model);
  }

  @override
  Future<PaginationModel<SegmentationModel>?> getSegmentation({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    var res = await remote.getSegmentation(token: token, queryParameters: queryParameters);
    return res;
  }

  @override
  Future<void> createSegmentation({required String token, required SegmentationModel model}) async {
    await remote.createSegmentation(token: token, model: model);
  }

  @override
  Future<void> editSegmentation({required String token, required SegmentationModel model}) async {
    await remote.editSegmentation(token: token, model: model);
  }

  @override
  Future<SegmentationModel?> deleteSegmentation({
    required String token,
    required String key,
  }) async {
    var res = await remote.deleteSegmentation(token: token, key: key);
    return res;
  }

  @override
  Future<BroadcastPrice?> getBroadcastPrice({required String token}) async {
    var res = await remote.getBroadcastPrice(token: token);
    return res;
  }

  //endregion

  //region local
  @override
  WidelyUsedLocalModel? getAllWidely() => local.getAllWidely();

  @override
  Future<void> initWidleyUsed() async {}

  @override
  Future<StewardSalesInfoDashboard?> getStewardSalesInfoDashboard({
    required String token,
    Map<String, dynamic>? queryParameters,
  }) async {
    return await remote.getStewardSalesInfoDashboard(
      token: token,
      queryParameters: queryParameters,
    );
  }

  //endregion
}
