package main

import (
	"fmt"
	"log"
	"os"
	"reflect"
	"time"

	. "escalation/jiraAWS/jira"

	"github.com/spf13/viper"
)

const LOG_FILE_PATH = "./log/jiraAWS.log"

// init the yaml file.
func setUpConfig() {
	viper.SetConfigName("conf")     // name of config file (without extension)
	viper.SetConfigType("yaml")     // REQUIRED if the config file does not have the extension in the name
	viper.AddConfigPath("./config") // optionally look for config in the working directory
	err := viper.ReadInConfig()     // Find and read the config file
	if err != nil {                 // Handle errors reading the config file
		log.Panic((fmt.Errorf("Fatal error config file: %w \n", err)))
	}
}

// init the log.
func initLog() {
	logFile, err := os.OpenFile(LOG_FILE_PATH, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
	if err != nil {
		panic(err)
	}
	log.SetOutput(logFile)
	log.SetPrefix("[JiraAWS]")
	log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
}

func main() {
	initLog()
	setUpConfig()
	t := time.Now().Unix()
	log.Println(reflect.TypeOf(t))
	var end string = time.Unix(t, 0).Format("2006/01/02")
	t -= 86400 //减一天
	var start string = time.Unix(t, 0).Format("2006/01/02")
	log.Println("now is: ", time.Unix(time.Now().Unix(), 0).Format("2006/01/02 15:04:05"))

	log.Println("start date:", start)
	log.Println("start date:", end)

	JiraAdd("op", start, end)   //op
	JiraAdd("tcoc", start, end) // tcoc
	JiraAdd("o11y", start, end) // o11y
	JiraAdd("gtoc", start, end) // gtoc

	Jiracompele()

}
