import {
    Actions,
    ActionType,
  } from './list.action';

  import {
    State,
    initialState,
  } from './list.state';

  import { Sensor } from '@overflow/commons-typescript/model/sensor';

  export function reducer(state = initialState, action: Actions): State {
    switch (action.type) {
      case ActionType.ReadAllByDomain: {
        return {
          ...state,
          error: null,
          pending: true,
        };
      }

      case ActionType.ReadAllByDomainSuccess: {
        return {
          ...state,
          error: null,
          pending: false,
          page: action.payload
        };
      }

      case ActionType.ReadAllByDomainFailure: {
        return {
          ...state,
          error: action.payload,
          pending: false,
          page: null,
        };
      }

      case ActionType.ReadAllByInfra: {
        return {
          ...state,
          error: null,
          pending: true,
        };
      }

      case ActionType.ReadAllByInfraSuccess: {
        return {
          ...state,
          error: null,
          pending: false,
          page: action.payload
        };
      }

      case ActionType.ReadAllByInfraFailure: {
        return {
          ...state,
          error: action.payload,
          pending: false,
          page: null,
        };
      }

      case ActionType.ReadAllByTarget: {
        return {
          ...state,
          error: null,
          pending: true,
        };
      }

      case ActionType.ReadAllByTargetSuccess: {
        return {
          ...state,
          error: null,
          pending: false,
          page: action.payload
        };
      }

      case ActionType.ReadAllByTargetFailure: {
        return {
          ...state,
          error: action.payload,
          pending: false,
          page: null,
        };
      }
      default: {
        return state;
      }
    }
  }
