package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
	"youngee_b_api/app/schedule"
	"youngee_b_api/config"
	_ "youngee_b_api/docs"
	"youngee_b_api/route"
	"youngee_b_api/service"
)

func main() {
	r := gin.Default()
	route.InitRoute(r)
	config := config.Init()
	// what?
	mailConfig := "./config/mail.json"
	service.SMTPMailServiceIstance.Init(mailConfig)

	addr := fmt.Sprintf("%v:%v", config.Host, config.Port)
	err := service.AutoTask()
	if err != nil {
		log.Println("service AutoTask error:", err.Error())
	}
	err1 := schedule.AutoTaskInvalid()
	if err1 != nil {
		log.Println("schedule AutoTaskInvalid error:", err1.Error())
	}
	err2 := schedule.AutoTaskRecharge()
	if err2 != nil {
		log.Println("schedule AutoTaskRecharge error:", err2.Error())
	}
	err3 := schedule.AutoTaskReview()
	if err3 != nil {
		log.Println("schedule AutoTaskReview error:", err3.Error())
	}
	err4 := schedule.AutoTaskSettle()
	if err4 != nil {
		log.Println("schedule AutoTaskSettle error:", err4.Error())
	}
	err5 := schedule.AutoTaskExecute()
	if err5 != nil {
		log.Println("schedule AutoTaskExecute error:", err5.Error())
	}
	r.Run(addr) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
