import { cityGetArchiveHatchingsService } from "../../../features/city/services/city-get-archive-hatchings";
import { cityGetHatchingInfo } from "../../../features/city/services/city-get-hatching-info";
import { cityGetHatchingInfoFull } from "../../../features/city/services/city-get-hatching-info-full";
import { cityGetHatchings } from "../../../features/city/services/city-get-hatchings";
import { cityGetHatchingsByAge } from "../../../features/city/services/city-get-hatchings-by-age";
import { cityGetPoultriesService } from "../../../features/city/services/city-get-poultries";
import { cityGetPoultryFarm } from "../../../features/city/services/city-get-poultry-farms";
import { cityGetProfile } from "../../../features/city/services/city-get-profile";
import { cityGetUserProfiles } from "../../../features/city/services/city-get-user-profiles";
import { getPoultryRequestsTotalQuantityService } from "../../../features/city/services/get-poultry-requests-total-quantity";
import { getSlaughtersKillRequestService } from "../../../features/city/services/get-slaughters-kill-request";
import { hourLimitKillRequestService } from "../../../features/city/services/hour-limit-kill-request";
import { checkRequestByCity } from "../../../features/file/services/checkRequestByCity";

export const cityExtraReducers = {
  [checkRequestByCity.fulfilled]: (state, { payload }) => {
    state.pending = false;
  },
  [checkRequestByCity.pending]: (state) => {
    state.pending = true;
  },
  [cityGetProfile.fulfilled]: (state, { payload }) => {
    state.profile = payload.data;
    state.pending = false;
  },
  [cityGetProfile.pending]: (state) => {
    state.pending = true;
  },
  [cityGetPoultryFarm.fulfilled]: (state, { payload }) => {
    state.poultryFarms = payload.data;
    state.pending = false;
  },
  [cityGetPoultryFarm.pending]: (state) => {
    state.pending = true;
  },
  [cityGetUserProfiles.fulfilled]: (state, { payload }) => {
    state.cityUsers = payload.data;
    state.pending = false;
  },
  [cityGetUserProfiles.pending]: (state) => {
    state.pending = true;
  },
  [cityGetHatchings.fulfilled]: (state, { payload }) => {
    state.hatchings = payload.data;
    state.pending = false;
  },
  [cityGetHatchingsByAge.fulfilled]: (state, { payload }) => {
    state.hatchings = payload.data;
    state.pending = false;
  },
  [cityGetHatchings.pending]: (state) => {
    state.pending = true;
  },
  [getPoultryRequestsTotalQuantityService.fulfilled]: (state, { payload }) => {
    state.poultryRequestsTotalQuantity = payload.data;
  },
  [hourLimitKillRequestService.fulfilled]: (state, { payload }) => {
    state.hourLimitKillRequest = payload.data;
  },
  [getSlaughtersKillRequestService.fulfilled]: (state, { payload }) => {
    state.getSlaughtersKillRequest = payload.data;
  },
  [cityGetArchiveHatchingsService.fulfilled]: (state, { payload }) => {
    state.cityGetArchiveHatchings = payload.data;
  },
  [cityGetPoultriesService.fulfilled]: (state, { payload }) => {
    state.cityGetPoultries = payload.data.map((item) => {
      return {
        label: `${item.unitName} (${item.address.city.name}) (${item.user.fullname}) (${item.user.mobile}) / ${item.lastHatchingRemainQuantity} قطعه`,
        value: item.user.mobile,
        disabled: item.lastHatchingRemainQuantity,
      };
    });
  },
  [cityGetHatchingInfo.fulfilled]: (state, { payload }) => {
    state.hatchingInfoWithDate = payload.data;
  },
  [cityGetHatchingInfoFull.fulfilled]: (state, { payload }) => {
    state.hatchingInfoFull = payload.data;
  },
};
