import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";

export const loginSendMobile = createAsyncThunk(
  "LOGIN_SEND_MOBILE",
  async ({ mobile, state }) => {
    const { data, status } = await axios.post("api/send/", { mobile, state });
    return { data, status };
  }
);
//buildchange
export const loginWithPassword = createAsyncThunk(
  "LOGIN_WITH_PASSWORD",
  async ({ mobile, password }) => {
    const { data, status } = await axios.post("api/login/", {
      username: mobile,
      password,
      // bushehr
      // api_key: "44d89a44-bd44-2144-a02f-2cc2cbf4e2d4",
      // kermanshah
      // api_key: "4b124231-62c7-41c6-8081-66191536c0b7",
      // test
      // api_key: "11d89a11-bd11-2111-a02f-2cc1cbf4e1d4",
      // markazi arak
      // api_key: "44d89a99-bd12-4152-a02f-5cc5cbf7e5d5",
      // hamedan
      // api_key: "33374d79-e8ee-4947-b0b4-4a6d31935814",
      // lorestan
      // api_key: "2b773c7e-f6de-4dd2-af43-a012a8b78d04",
      // test
      // api_key: "11d89a11-bd11-2111-a02f-2cc1cbf4e1d4",
      // ardebil (AR)
      // api_key: "14d14a14-bd14-1414-a03f-2cc1cbf5e1d1",
      // tabriz (sharghi)
      // api_key: "23d23a32-bd23-2311-a03f-2cc1cbf3e1d4",
    });
    return { data, status };
  }
);

export const forgetPassword = createAsyncThunk(
  "LOGIN_FORGET_PASSWORD",
  async ({ mobile, state }) => {
    const { data, status } = await axios.post("api/send/", { mobile, state });
    return { data, status };
  }
);

export const checkUserPath = createAsyncThunk(
  "CHECK_USER_PATH",
  async ({ mobile, state }) => {
    const { data, status } = await axios.post(
      "https://userbackend.rasadyar.com/api/send_otp/",
      { mobile, state }
    );
    return { data, status };
  }
);

export const checkActiveUsers = createAsyncThunk(
  "CHECK_ACTIVE_USERS",
  async () => {
    const { data, status } = await axios.get(
      "https://userbackend.rasadyar.com/api/active-users/"
    );
    return { data, status };
  }
);

export const forgetPasswordSendOpt = createAsyncThunk(
  "LOGIN_FORGET_PASSWORD_SEND_OTP",
  async ({ key, code }) => {
    const { data, status } = await axios.post("api/check/", { key, code });
    return { data, status };
  }
);

export const forgetPasswordChangePassword = createAsyncThunk(
  "LOGIN_FORGET_PASSWORD_CHANGE_PASSWORD",
  async ({ username, password }) => {
    const { data, status } = await axios.post("api/forget/", {
      username,
      password,
    });
    return { data, status };
  }
);

export const changePassword = createAsyncThunk(
  "LOGIN_CHANGE_PASSWORD",
  async ({ username, password }) => {
    const { data, status } = await axios.post("api/change_password/", {
      username,
      password,
    });
    return { data, status };
  }
);
