import * as actionTypes from '../constants/actionTypes';
import initialState from "./initialState";

const contractReducer = (state = initialState.contract, action) => 
{
	switch (action.type) 
	{
		case actionTypes.CONTRACT: 
		{
			return {
				...state, 
				...action.data, 
			};
		}

		case actionTypes.CONTRACT_PAYMENTS: 
		{
			return {
				...state, 
				payments: action.data.payments, 
				avans: action.data.avans, 
				debt: action.data.debt, 
				penalty: action.data.penalty, 
			};
		}

		case actionTypes.CONTRACT_INFO: 
		{
			return {
				...state, 
				date: action.data.date, 
				car: action.data.car, 
			};
		}

		case actionTypes.CONTRACT_INSURANCE: 
		{
			return {
				...state, 
				insurance: action.data.insurance, 
			};
		}

		case actionTypes.CONTRACT_HELPCARD: 
		{
			return {
				...state, 
				helpcard: action.data.helpcard, 
			};
		}

		case actionTypes.CONTRACT_REGISTRATION: 
		{
			return {
				...state, 
				registration: action.data.registration, 
			};
		}

		case actionTypes.CONTRACT_TELEMATIC: 
		{
			return {
				...state, 
				telematic: action.data.telematic, 
			};
		}

		case actionTypes.CONTRACT_AGREEMENT: 
		{
			return {
				...state, 
				agreement: action.data.agreement, 
			};
		}

		case actionTypes.CONTRACT_DOCUMENTS: 
		{
			return {
				...state, 
				documents: action.data.documents, 
			};
		}

		case actionTypes.CONTRACT_FINES: 
		{
			return {
				...state, 
				fines: action.data.fines, 
			};
		}

		case actionTypes.CONTRACT_RULES: 
		{
			return {
				...state, 
				rules: action.data.rules, 
			};
		}

		case actionTypes.CONTRACT_MATERIALS: 
		{
			return {
				...state, 
				materials: action.data.materials, 
			};
		}

		case actionTypes.CONTRACT_CHANGE: 
		{
			return {
				...state, 
				...{ change: { ...state.change, ...action.data } }, 
			};
		}

		default: {
			return state;
		}
	}
};

export default contractReducer;