package main

import (
	"ai_developer_admin/libs/cronjob"
	"ai_developer_admin/libs/mysql"
	"ai_developer_admin/libs/registry"
	_ "ai_developer_admin/routers"
	"fmt"
	beego "github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/server/web/filter/cors"
	_ "github.com/beego/beego/v2/server/web/session/redis"
	"time"
)

func init() {
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-Xsrf-Token"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "X-Xsrf-Token", "Authorization"},
		AllowCredentials: true,
	}))
	beego.SetStaticPath("/uploads", "uploads")
}

func main() {
	//t := time.Now()
	//temp := fmt.Sprintf(t.Format("2006-01-02T15:04:05.000000Z"))
	//logs.Debug("temp = ", temp)

	//log.InitLog(log.LogConfig{Path: "logs", Level: "debug", Save: 3})

	//level, _ := beego.AppConfig.Int("logLevel")
	//logs.SetLevel(level)
	//fileName, _ := beego.AppConfig.String("logfile")
	//if fileName != "" {
	//	config := fmt.Sprintf("{\"filename\":\"%s\"}", fileName)
	//	logs.SetLogger(logs.AdapterFile, config)
	//}

	str := "2024-02-01T18:41:30"
	layout := "2006-01-02T15:04:05"
	t, _ := time.Parse(layout, str)
	fmt.Print("t = %s", t)
	//currentTime := time.Now()
	////if appRequest.EndTime == nil {
	//tempendTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 23, 59, 59, 0, currentTime.Location())
	//endTime := &tempendTime
	////}
	////if appRequest.StartTime == nil {
	//temp := fmt.Sprintf("-%dh", 24*7)
	//m, _ := time.ParseDuration(temp)
	//tempTime := currentTime.Add(m)
	//tempTime = time.Date(tempTime.Year(), tempTime.Month(), tempTime.Day(), 0, 0, 0, 0, tempTime.Location())
	//startTime := &tempTime
	////}
	//startTimeStr := fmt.Sprintf(startTime.Format("2006-01-02T15:04:05.000000Z"))
	//endTimeStr := fmt.Sprintf(endTime.Format("2006-01-02T15:04:05.000000Z"))
	//
	//dates := utils.SplitDate(startTimeStr, endTimeStr, "2006-01-02T15:04:05.000000Z")
	//logs.Debug("dates = ", dates)

	cronjob.Start()
	mysql.GetMysqlInstace()
	//postgres.Query("")
	registry.RegistryBackend()
	beego.Run()

	//id, err := snowflake.NextId()
	//if err != nil {
	//	logs.Debug("dates = ", err.Error())
	//}
	//logs.Debug("id = ", id)
	//id, err = snowflake.NextId()
	//if err != nil {
	//	logs.Debug("dates = ", err.Error())
	//}
	//logs.Debug("id = ", id)
}
