import { loginUser, logOutUser } from '@/services/system/api_login'

export default {
    namespace: 'login',
    state: {
        data: {}
    },
    effects: {
        *login_user({ payload, callback }, { call, put }) {
            const response = yield call(loginUser, payload)
            yield put({
                type: 'loginUser',
                payload: response
            })

            if (callback) callback(response)
        },
        *login_out_user({ payload, callback }, { call, put }) {
            const response = yield call(logOutUser, payload)
            yield put({
                type: 'logOutUser',
                payload: response
            })

            if (callback) callback(response)
        }
    },
    reducers: {
        loginUser(state, { payload }) {
            return {
                ...state,
                data: { ...payload }
            }
        },
        logOutUser(state, { payload }) {
            return {
                ...state,
                data: { ...payload }
            }
        }
    }
}
