package server

import (
	"local/firestormy/scheduler"
	"time"
)

func toMap(j *scheduler.Job) map[string]interface{} {
	tz, err := time.LoadLocation("America/Denver")
	if err != nil {
		panic(err)
	}
	out := make(map[string]interface{})
	out["disabled"] = j.Disabled
	out["id"] = j.Name
	out["title"] = j.Title
	out["cron"] = j.Schedule
	out["language"] = j.Runner.String()
	out["script"] = j.Raw
	out["last"] = map[string]interface{}{
		"run":     j.LastRun.In(tz).Format(`2006-01-02 15:04:05 MST`),
		"runtime": j.LastRuntime.String(),
		"output":  j.LastOutput,
		"status":  j.LastStatus,
	}
	return out
}
