import { MapService } from './../map.service';
import { AppState } from 'src/app/store/app.reducers';
import { MapAttack } from '../model/MapAttack.model';
import { MapActions, SET_MAP_ATTACKS, SET_MAP_TOKEN, SET_MAP_DATA, SET_MAP_SETTINGS } from './map.actions';
import { MapSettings } from '../model/MapSettings.model';

export interface MapFeatureState extends AppState{
    map: MapState;
}

export interface MapState{
    attacks: MapAttack[];
    settings: MapSettings;
    token: string;
}

const initialState: MapState = {
    attacks: null,
    settings: null,
    token: null
}

export function mapReducers(state = initialState, action: MapActions){
    switch(action.type){
        case SET_MAP_ATTACKS:
            return {
                ...state,
                attacks: action.attacks
            }
        case SET_MAP_DATA:
            return {
                ...state,
                attacks: action.mapData.mapAttacks,
                settings: action.mapData.mapSettings
            }
        case SET_MAP_SETTINGS:
            return {
                ...state,
                settings: action.mapSettings
            }
        case SET_MAP_TOKEN:
            return {
                ...state,
                token: action.token
            }
        default:
            return state;
    }
}