/**
 * Created by radko on 13.06.17.
 */

import localAuth from './../../localAuth'
import VapiWrapper from './../VapiWrapper'
import Pouzivatel from './../models/Pouzivatel'

export default class PouzivateliaStore extends VapiWrapper {
  constructor (baseUrl) {
    super (
      baseUrl,
      {
        state: {
          pouzivatel: new Pouzivatel({}),
          pouzivatelia: []
        }
      })
      .post({
        action: 'prihlasenie',
        property: 'pouzivatel',
        path: () => `/prihlasenie`,
        onSuccess: (state, payload) => {
          localAuth.ulozitUdajePouzivatela(payload.data)
          state.pouzivatel = new Pouzivatel(payload.data)
        }
      })
      .get({
        action: 'ziskajUdajeOAutentifikovanomPouzivatelovi',
        property: 'pouzivatel',
        path: () => `/pouzivatel`,
        onSuccess: (state, payload) => {
          state.pouzivatel = new Pouzivatel(payload.data)
        }
      })
  }
}
