import { Customer } from 'src/app/models/customer.model';
import { CustomerSaleAction, CustomerSaleActionTypes } from '../actions/customer-sale.action';

export interface CustomerSaleState {
  item: Customer;
  loading: boolean;
  error: Error;
}

const initialState: CustomerSaleState = {
  item: null,
  loading: false,
  error: undefined
};

export function CustomerSaleReducer(state: CustomerSaleState = initialState, action: CustomerSaleAction) {
  switch (action.type) {
    case CustomerSaleActionTypes.SELECT_CUSTOMER:
      return {
        ...state,
        item: action.payload,
        loading: false
      };
    case CustomerSaleActionTypes.SELECT_CUSTOMER_SUCCESS:
      return {
        ...state,
        item: action.payload,
        loading: false
      };
    case CustomerSaleActionTypes.SELECT_CUSTOMER_FAILURE:
      return {
        ...state,
        error: action.payload,
        loading: false
      };
    case CustomerSaleActionTypes.LOAD_CUSTOMER:
      return {
        ...state,
        loading: false
      };
    case CustomerSaleActionTypes.LOAD_CUSTOMER_SUCCESS:
      return {
        ...state,
        item: action.payload,
        loading: false
      };
    case CustomerSaleActionTypes.LOAD_CUSTOMER_FAILURE:
      return {
        ...state,
        error: action.payload,
        loading: false
      };
    default:
      return state;
  }
}



