import { provinceFinancialGetFinalFactorsService } from "../../../features/province-finacial/services/province-financial-get-final-factors-service";
import { provinceFinancialGetFinancialHistory } from "../../../features/province-finacial/services/province-financial-get-financial-history";
import { provinceFinancialGetPayedFactorsService } from "../../../features/province-finacial/services/province-financial-get-payed-factors-service";
import { provinceFinancialGetPendingRequestsService } from "../../../features/province-finacial/services/province-financial-get-pending-requests";
import { provinceFinancialGetRegisteredComplaints } from "../../../features/province-finacial/services/province-financial-get-registered-compaints";
import { provinceFinancialGetRequests } from "../../../features/province-finacial/services/province-financial-get-requests";
import { provinceFinancialGetSlaughterSattlementService } from "../../../features/province-finacial/services/province-financial-get-slaughter-sattlement-service";
import { provinceFinancialGetTransactionInfo } from "../../../features/province-finacial/services/province-financial-get-transaction-info";
import { provinceFinancialGetUserFinancialInfo } from "../../../features/province-finacial/services/province-financial-get-user-financial-info";
import { provinceFinancialGetUsersWaletinfo } from "../../../features/province-finacial/services/province-financial-get-users-walet-info";
import { ticketGetOperatorTickets } from "../../../features/ticket/services/ticket-get-operator-tickets";

export const provinceFinancialExtraReducers = {
  [provinceFinancialGetRequests.fulfilled]: (state, { payload }) => {
    state.provinceFinancial = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetRequests.pending]: (state) => {
    state.pending = true;
  },
  [ticketGetOperatorTickets.fulfilled]: (state, { payload }) => {
    state.tickets = payload.data;
    state.pending = false;
  },
  [ticketGetOperatorTickets.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetUsersWaletinfo.fulfilled]: (state, { payload }) => {
    state.userWaletInfo = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetUsersWaletinfo.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetRegisteredComplaints.fulfilled]: (
    state,
    { payload }
  ) => {
    state.registeredComplaints = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetRegisteredComplaints.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetUserFinancialInfo.fulfilled]: (state, { payload }) => {
    state.userFinancialInfo = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetUserFinancialInfo.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetFinancialHistory.fulfilled]: (state, { payload }) => {
    state.financialHistory = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetFinancialHistory.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetTransactionInfo.fulfilled]: (state, { payload }) => {
    state.transactionInfo = payload.data;
    state.pending = false;
  },
  [provinceFinancialGetTransactionInfo.pending]: (state) => {
    state.pending = true;
  },
  [provinceFinancialGetPendingRequestsService.fulfilled]: (
    state,
    { payload }
  ) => {
    const pendingRequestsData = Array.isArray(payload.data)
      ? payload.data
      : payload.data?.results || [];
    state.provinceFinancialGetPendingRequests = pendingRequestsData;
  },
  [provinceFinancialGetPayedFactorsService.fulfilled]: (state, { payload }) => {
    state.provinceFinancialGetPayedFactors = payload.data;
  },
  [provinceFinancialGetFinalFactorsService.fulfilled]: (state, { payload }) => {
    state.provinceFinancialGetFinalFactors = payload.data;
  },
  [provinceFinancialGetSlaughterSattlementService.fulfilled]: (
    state,
    { payload }
  ) => {
    state.provinceFinancialGetSlaughterSattlement = payload.data;
  },
};
