import { slaughterGetCars } from "../../../features/slaughter-house/services/slaughter-get-cars";
import { slaughterGetRequests } from "../../../features/slaughter-house/services/salughter-get-requests";
import { slaughterGetActiveRequests } from "../../../features/slaughter-house/services/slaughter-get-active-requests";
import { slaughterGetProfile } from "../../../features/slaughter-house/services/slaughter-get-profile";
import { slaughterGetComplaints } from "../../../features/slaughter-house/services/slaughter-get-complaints";
import { slaughterGetRegisteredComplaints } from "../../../features/slaughter-house/services/slaughter-get-registered-complaints";
import { slaughterGetInventoryBars } from "../../../features/slaughter-house/services/slaughter-get-inventory-bars";
import { slaughterGetKillerKillhousesService } from "../../../features/slaughter-house/services/slaughter-get-killers-killhouses";
import { slaughterFactorsService } from "../../../features/slaughter-house/services/slaughter-factors";
import { slaughterFinalFactorsService } from "../../../features/slaughter-house/services/slaughter-final-factors";
import { slaughterGetBarInfoRequestsService } from "../../../features/slaughter-house/services/slaughter-get-bar-info-requests";
import { slaughterGetPayFactorRequestsService } from "../../../features/slaughter-house/services/slaughter-get-pay-factor-requests";
import { slaughterGetPermissionToVetService } from "../../../features/slaughter-house/services/slaughter-get-premisson-to-vet";
import { slaughterGetAllocatedCarsService } from "../../../features/slaughter-house/services/slaughter-get-allocated-cars";
import { slaughterGetPaiedFactorsService } from "../../../features/slaughter-house/services/slaughter-get-paied-factors";
import { slaughterManageBarsService } from "../../../features/slaughter-house/services/slaughter-manage-bars";
import { slaughterGetInventoryStock } from "../../../features/slaughter-house/services/salughter-get-inventory-stock";
import { slaughterGetInventoryFreeBarsService } from "../../../features/slaughter-house/services/slaughter-get-inventory-free-bars";
import { slaughterInventoryBarsService } from "../../../features/slaughter-house/services/slaughter-inventory-bars";
import { slaughterGetStewardsService } from "../../../features/slaughter-house/services/slaughter-get-stewards";
import { slaughterGetKillhouseStewardsService } from "../../../features/slaughter-house/services/slaughter-get-killhouse-stewards";
import { slaughterGetGuildsService } from "../../../features/slaughter-house/services/slaughter-get-guilds";
import { slaughterManageInventoryAllocationsService } from "../../../features/slaughter-house/services/salughter-manage-inventory-allocations";
import { slaughterGetUpdatedInventoryStock } from "../../../features/slaughter-house/services/salughter-get-updated-inventory-stock";
import { slaughterGetKillhouseGuildsService } from "../../../features/slaughter-house/services/slaughter-get-killhouse-guilds";
import { slaughterGetPoultriesService } from "../../../features/slaughter-house/services/salughter-get-poultries";
import { slaughterGetKillhousesService } from "../../../features/slaughter-house/services/slaughter-get-killhouses";
import { slaughterGetAggregateLoadInformationService } from "../../../features/slaughter-house/services/salughter-get-aggregate-load-information";
import { slaughterManageInventoryAllocationForFreezingService } from "../../../features/slaughter-house/services/slaughter-manage-inventory-allocation-for-freezing";
import { slaughterGetOutOfProvinceSells } from "../../../features/slaughter-house/services/slaughter-get-out-of-province-sells";
import { slaughterGetPermisionState } from "../../../features/slaughter-house/services/slaughter-get-permision";
import { slaughterGetPaymentOverviewInfo } from "../../../features/slaughter-house/services/slaughter-get-payment-overview-info";
import { slaughterGetPaymentByWeightOverview } from "../../../features/slaughter-house/services/slaughter-get-payment-by-weight-overview";
import { slaughterGetProductsService } from "../../../features/slaughter-house/services/slaughter-inventory-gets";
import { getKillhouseApprovedPriceState } from "../../../features/province/services/get-approved-price-state";
import { slaughterGetVBroadcastInfo } from "../../../features/slaughter-house/services/slaughter-get-distribution-info";
import { fetchSlaughterBroadcastAndProducts } from "../../../features/slaughter-house/services/handle-fetch-slaughter-products";

export const slaughterExtraReducer = {
  [slaughterGetCars.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterHouseCars = payload.data;
  },
  [slaughterGetProfile.fulfilled]: (state, { payload }) => {
    state.profile = payload.data;
    state.inventorySelectedKillHouse = payload.data.killHouse[0]?.key;
    state.pending = false;
  },
  [slaughterGetCars.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetRequests.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterRequests = payload.data;
  },
  [slaughterGetRequests.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetActiveRequests.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterActiveRequests = payload.data;
  },
  [slaughterGetKillhousesService.fulfilled]: (state, { payload }) => {
    state.slaughterGetKillhouses = payload.data;
  },
  [slaughterGetAggregateLoadInformationService.fulfilled]: (
    state,
    { payload }
  ) => {
    state.slaughterGetAggregateLoadInformation = payload.data;
  },
  [slaughterGetActiveRequests.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetComplaints.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterHouseComplaints = payload.data;
  },
  [slaughterGetComplaints.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetRegisteredComplaints.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterHouseRegisteredComplaints = payload.data;
  },
  [slaughterGetRegisteredComplaints.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetInventoryBars.fulfilled]: (state, { payload }) => {
    state.pending = false;
    state.slaughterHouseInventoryBars = payload.data;
  },
  [slaughterGetInventoryBars.pending]: (state) => {
    state.pending = true;
  },
  [slaughterGetKillerKillhousesService.fulfilled]: (state, { payload }) => {
    state.slaughterGetKillerKillhouses = payload.data;
  },
  [slaughterFactorsService.fulfilled]: (state, { payload }) => {
    state.slaughterFactors = payload.data;
  },
  [slaughterFinalFactorsService.fulfilled]: (state, { payload }) => {
    state.slaughterFinalFactors = payload.data;
  },
  [slaughterGetBarInfoRequestsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetBarInfoRequests = payload.data;
  },
  [slaughterGetPayFactorRequestsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetPayFactorRequests = payload.data;
  },
  [slaughterGetPermissionToVetService.fulfilled]: (state, { payload }) => {
    state.slaughterGetPermissionToVet = payload.data;
  },
  [slaughterGetAllocatedCarsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetAllocatedCars = payload.data;
  },
  [slaughterGetPaiedFactorsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetPaiedFactors = payload.data;
  },
  [slaughterManageBarsService.fulfilled]: (state, { payload }) => {
    state.slaughterManageBars = payload.data;
  },
  [slaughterGetInventoryStock.fulfilled]: (state, { payload }) => {
    state.slaughterGetInventoryStockData = payload.data;
  },
  [slaughterGetInventoryFreeBarsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetInventoryFreeBars = payload.data;
  },
  [slaughterInventoryBarsService.fulfilled]: (state, { payload }) => {
    state.slaughterInventoryBars = payload.data;
  },
  [fetchSlaughterBroadcastAndProducts.fulfilled]: (state, { payload }) => {
    state.slaughterProducts = payload.productsData;
    state.distributionInfo = payload.broadcastData;
  },
  [slaughterGetProductsService.fulfilled]: (state, { payload }) => {
    state.slaughterProducts = payload.data;
  },
  [slaughterGetVBroadcastInfo.fulfilled]: (state, { payload }) => {
    state.distributionInfo = payload.data;
  },
  [getKillhouseApprovedPriceState.fulfilled]: (state, { payload }) => {
    state.priceInfo = payload.data;
  },
  [slaughterGetStewardsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetStewards = payload.data.map((item) => ({
      label: `${item.guilds.guildsName} (${item.guilds.user.city}) / ${item.guilds.user.fullname} (${item.guilds.user.mobile})`,
      value: item.key,
    }));
  },
  [slaughterGetKillhouseStewardsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetKillhouseStewards = payload.data;
  },
  [slaughterGetUpdatedInventoryStock.fulfilled]: (state, { payload }) => {
    state.slaughterUpdatedInventoryStock = payload.data;
  },
  [slaughterManageInventoryAllocationsService.fulfilled]: (
    state,
    { payload }
  ) => {
    state.slaughterManageInventoryAllocations = payload.data;
  },
  [slaughterManageInventoryAllocationForFreezingService.fulfilled]: (
    state,
    { payload }
  ) => {
    state.slaughterManageInventoryAllocationsForFreezing = payload.data;
  },
  [slaughterGetGuildsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetGuilds = payload.data.map((item) => ({
      label: `${item.guildsName} (${item.user.city}) / ${item.user.fullname} (${item.user.mobile})`,
      value: item.key,
    }));
  },
  [slaughterGetKillhouseStewardsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetKillhouseStewards = payload.data;
  },
  [slaughterGetOutOfProvinceSells.fulfilled]: (state, { payload }) => {
    state.slaughterOutOfProvinceSellsState = payload.data;
  },
  [slaughterGetKillhouseGuildsService.fulfilled]: (state, { payload }) => {
    state.slaughterGetKillhouseGuilds = payload.data;
  },
  [slaughterGetPoultriesService.fulfilled]: (state, { payload }) => {
    state.slaughterGetPoultries = payload.data;
  },
  [slaughterGetPermisionState.fulfilled]: (state, { payload }) => {
    state.slaughterPermissionState = payload.data?.permission;
    state.slaughterExclusiveState = payload.data?.exclusive;
  },
  [slaughterGetPaymentOverviewInfo.fulfilled]: (state, { payload }) => {
    state.slaughterPaymentOverview = payload.data;
  },
  [slaughterGetPaymentByWeightOverview.fulfilled]: (state, { payload }) => {
    state.slaughterPaymentByWeightOverview = payload.data;
  },
};
