package stat_service

import (
	"chain33-pai/models"
)

type RaspMinerStat struct {
	Addr string `json:"addr"`
	MinedAmount int64 `json:"mined_amount"`
	Height int64 `json:"height"`
	Time int64 `json:"time"`
}

func (s *RaspMinerStat) GetMinerStat(addr string) (*models.RaspMinerStat,error) {
	return  models.GetAddr(addr)
}

func (s *RaspMinerStat) SetMineTime(addr string,start ,end int64) error {
	stat,err := models.GetAddr(addr)
	if err != nil {
		return err
	}
	m := map[string]interface{}{"miner_start_time":start,"miner_end_time":end}
	if stat.MinerStartTime <= 0 {
		m["miner_start_time"] = start
		m["miner_end_time"] = 0
	}
	if stat.MinerStartTime > 0 && stat.MinerEndTime <= 0 {
		m["miner_start_time"] = stat.MinerStartTime
		m["miner_end_time"] = end
	}

	return models.EditAddr(addr,m)
}

