import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";

export const provinceSubSectorCitySharesWageDetailsDashboard = createAsyncThunk(
  "SUB_SECTOR_CITY_SHARES_DASHBOARD",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      "/union-subsector-wage-dashboard",
      {
        params: { ...d },
      }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);
export const provinceSubSectorCitySharesDepositssDashboard = createAsyncThunk(
  "SUB_SECTOR_DEPOSITS_DASHBOARD",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      "/union-subsector-transaction-dashboard"
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorCitySharesWageDetailsService = createAsyncThunk(
  "SUB_SECTOR_CITY_SHARES",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/city-operator-for-sub-sector", {
      params: { ...d },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorCitySharesGeyCitisService = createAsyncThunk(
  "SUB_SECTOR_CITY_SHARES",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      "/city-operator-for-sub-sector/?operators=true"
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorCitySharesWageDetailsSubmitDepositService =
  createAsyncThunk("CREATE_TRANSACTION", async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.post("sub-sector-transactions/", d);
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response.data.result };
    }
  });

export const provinceSubSectorCitySharesWageDetailsEditDepositService =
  createAsyncThunk("CREATE_TRANSACTION", async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.put("sub-sector-transactions/0/", d);
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response.data.result };
    }
  });

export const provinceSubSectorCitySharesWageDetailsDeleteDepositService =
  createAsyncThunk("DELETE_TRANSACTION", async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.delete("sub-sector-transactions/0/", {
      params: {
        transaction_key: d,
      },
    });
    dispatch(LOADING_END());
    return { data, status };
  });

export const provinceSubSectorCitySharesService = createAsyncThunk(
  "SUB_SECTOR_SHARES",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      "/sub-sector-wage-type-percentage/?type=" + d
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorCitySharesSharesService = createAsyncThunk(
  "EDIT_SHARE",
  async (d, { dispatch }) => {
    try {
      dispatch(LOADING_START());
      const { data, status } = await axios.put(
        "sub-sector-wage-type-percentage/0/",
        d
      );
      dispatch(LOADING_END());
      return { data, status };
    } catch (e) {
      dispatch(LOADING_END());
      return { error: e.response.data.result };
    }
  }
);

// vetFarm

export const provinceSubSectorVetFarmSharesOverviewDashboard = createAsyncThunk(
  "SUB_SECTOR_VETFARM_SHARES_DASHBOARD",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/vet_dashboard_wage", {
      params: { ...d },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorVetFarmSharesVetFarmsService = createAsyncThunk(
  "SUB_SECTOR_VETFARM_SHARES",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/vet_for_sub_sector", {
      params: { ...d },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorVetFarmSharesGeyVetFarmsService =
  createAsyncThunk("SUB_SECTOR_VET_FARMS_SHARES", async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/vet_for_sub_sector_transaction");
    dispatch(LOADING_END());
    return { data, status };
  });

// guild
export const provinceSubSectorStewardSharesGeyVetFarmsService =
  createAsyncThunk(
    "SUB_SECTOR_STEWARD_FARMS_SHARES",
    async (d, { dispatch }) => {
      dispatch(LOADING_START());
      const { data, status } = await axios.get(
        "/city-guild-for-sub-sector-transactions"
      );
      dispatch(LOADING_END());
      return { data, status };
    }
  );

export const provinceSubSectorStewardSharesOverviewDashboard = createAsyncThunk(
  "SUB_SECTOR_STEWARD_SHARES_DASHBOARD",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/city-guild-wage-dashboard", {
      params: { ...d },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceSubSectorStewardSharesStewardsService = createAsyncThunk(
  "SUB_SECTOR_STEWARD_SHARES",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("/city-guild-for-sub-sector");
    dispatch(LOADING_END());
    return { data, status };
  }
);
