import {createReducer} from '@reduxjs/toolkit';
import {
  setAutoInstallRelease,
  setDismissDependencies,
  setInstallActive,
  setInstallComplete,
  setInstallTestActive,
  setMissingDependencies
} from '../actions/install_actions';

export const installReducer = createReducer({
  AutoInstallRelease: false,
  DismissDependencies: false,
  InstallActive: false,
  InstallResult: null,
  InstallTestActive: false,
  InstallType: null,
  MissingDependencies: [],
}, {
  [setAutoInstallRelease]: (state, action) => {
    return {
      ...state,
      AutoInstallRelease: action.payload,
    }
  },
  [setDismissDependencies]: (state, action) => {
    return {
      ...state,
      DismissDependencies: action.payload,
    }
  },
  [setInstallActive]: (state, action) => {
    return {
      ...state,
      InstallActive: true,
      InstallResult: null,
      InstallType: action.payload,
    };
  },
  [setInstallComplete]: (state, action) => {
    return {
      ...state,
      InstallActive: false,
      InstallResult: action.payload,
      InstallType: null,
    }
  },
  [setInstallTestActive]: (state, action) => {
    return {
      ...state,
      InstallTestActive: action.payload,
    }
  },
  [setMissingDependencies]: (state, action) => {
    return {
      ...state,
      MissingDependencies: action.payload,
    }
  }
});
