package main

import (
	"encoding/json"
	"errors"
	"io/ioutil"
	"log"
)

//PathsConfig all system available pathes
type PathsConfig struct {
	Angular2App    string `json:"angular2_app"`
	SinglePageEdit string `json:"singlePageEdit"`
	ThisSiteURL    string `json:"thisSiteURL"`
}

//GlobalPath all global pathes configurations
var GlobalPath = PathsConfig{}

func (m *PathsConfig) readConfig() error {
	log.Printf("read Path config from %s\r\n", "path_config.json")
	body, err := ioutil.ReadFile("path_config.json")
	if err != nil {
		log.Fatal("Cannot read config from path_config.json")
		return err
	}
	err = json.Unmarshal(body, m)
	if m.SinglePageEdit == "" {
		return errors.New("Single Page Edit Resources not available")
	}

	if m.Angular2App == "" {
		return errors.New("Angular2APP path not available")
	}

	if m.ThisSiteURL == "" {
		return errors.New("site url not available")
	}

	return err
}
