package core

import (
	"encoding/json"
	"io/ioutil"
	"os"
	"time"
)

//LastPatchTime 存放各种时间，用于智能版本更新
type LastPatchTime struct {
	ViewZipTime          time.Time
	StaticZipTime        time.Time
	InstitutionApplyTime time.Time //制度应用的时间
	InstitutionZipTime   time.Time //制度包zip文件最后修改时间
}

//Save 保存配置到磁盘上
func (config *LastPatchTime) Save() error {
	bys, err := json.MarshalIndent(config, "", "\t")
	if err != nil {
		return (err)
	}
	if err = ioutil.WriteFile(DataFile("patchtime.json"), bys, os.ModePerm); err != nil {
		return (err)
	}

	return nil
}

//ReadPatchTime 读取磁盘配置
func ReadPatchTime() *LastPatchTime {
	config := &LastPatchTime{}
	if bys, err := ioutil.ReadFile(DataFile("patchtime.json")); err == nil {
		err = json.Unmarshal(bys, config)
		if err != nil {
			LOG.Panic(err)
		}
	}
	return config
}
