import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';

interface CounterState {
    value: number;
}

const initialState: CounterState = {
    value: 0,
};

const counterSlice = createSlice({
    name: 'counter',
    initialState,
    reducers: {
        increment: (state) => {
            state.value += 1;
        },
        decrement: (state) => {
            state.value -= 1;
        },
        incrementByAmount: (state, action: PayloadAction<number>) => {
            state.value += action.payload;
        },
    },
});

export const { increment, decrement, incrementByAmount } = counterSlice.actions;

export const apple = createAsyncThunk('user/wxLogin', async (payload: { code: string }, { dispatch }) => {
    dispatch(increment());
    // console.log(payload.code)
    // request({
    //     url: API_LOGIN, method: 'POST', data: { 'code':payload.code,type:'WX_MP',app_version:'1',client_version:'1',client_type:'WXP_MP' }
    // }).then(res => {
    //     console.log(res);
    //     dispatch(loginSuccess(res));
    // })
});

export default counterSlice.reducer;