import {
  CHECK_SMS_KEY,
  CREATE_USER,
  FETCH_USER,
  FORGET_PASSWORD,
  RESET_PASSWORD,
  SEND_SMS_KEY,
  UPDATE_MOBILE,
  UPDATE_PASSWORD,
  UPDATE_USER_DATA
} from '../constants/user';
import { CREATE_USER_URL, FETCH_USER_URL, UPDATE_USER_URL } from '../urls/user';

export function fetchUserData() {
  return {
    type: FETCH_USER,
    api: true,
    auth: true,
    cache: 5 * 60,
    payload: {
      method: 'GET',
      url: FETCH_USER_URL
    }
  };
}

export function createUser(data) {
  return {
    type: CREATE_USER,
    api: true,
    payload: {
      method: 'POST',
      url: CREATE_USER_URL,
      data
    }
  };
}

export function updateUserData(data) {
  return {
    type: UPDATE_USER_DATA,
    api: true,
    auth: true,
    payload: {
      method: 'PATCH',
      url: UPDATE_USER_URL,
      data
    }
  };
}

export function updateMobileRequest(mobile, uid, smsKey) {
  return {
    type: UPDATE_MOBILE,
    api: true,
    auth: true,
    payload: {
      method: 'PATCH',
      url: UPDATE_USER_URL,
      data: { mobile, uid, smsKey }
    }
  };
}

export function updatePasswordRequest(password) {
  return {
    type: UPDATE_PASSWORD,
    api: true,
    auth: true,
    payload: {
      method: 'PATCH',
      url: UPDATE_USER_URL,
      data: { password }
    }
  };
}

export function sendSMSKeyRequest(mobile) {
  return {
    type: SEND_SMS_KEY,
    api: true,
    auth: true,
    payload: {
      method: 'PATCH',
      url: '/users/users/send-sms-key',
      data: { mobile }
    }
  };
}

export function checkSMSKeyRequest(uid, smsKey) {
  return {
    type: CHECK_SMS_KEY,
    api: true,
    payload: {
      method: 'PATCH',
      url: `/users/users/check-sms-key/${uid}`,
      data: { smsKey }
    }
  };
}

export function forgetPasswordRequest(mobile) {
  return {
    type: FORGET_PASSWORD,
    api: true,
    payload: {
      method: 'PATCH',
      url: '/users/users/send-sms-key',
      data: { mobile }
    }
  };
}

export function resetPasswordRequest(uid, token, password) {
  return {
    type: RESET_PASSWORD,
    api: true,
    payload: {
      method: 'PATCH',
      url: `/users/users/forget-password/reset-password/${uid}/${token}`,
      data: { password }
    }
  };
}
