import { createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';
import { Token, LoginParams } from './types';
import pickBy from 'lodash/pickBy';
import identity from 'lodash/identity';

export const fetchToken = createAsyncThunk<Token[], LoginParams>(
  'token/fetchTokenStatus',
  async (params) => {
    const { login, password } = params;
    const { data } = await axios.post<Token[]>('/api/login', {
      params: pickBy(
        {
          login: login,
          password: password,
        },
        identity,
      ),
    });
    console.log(data, 4444);
    return data;
  },
);
