package initialize

import (
	"fmt"
	"sundynix-go/global"
	"sundynix-go/task"

	"github.com/robfig/cron/v3"
	"go.uber.org/zap"
)

func InitTimer() {
	go func() {
		var option []cron.Option
		option = append(option, cron.WithSeconds())

		// 任务一:每天8点30执行 发送植物养护提醒
		_, err := global.Timer.AddTaskByFuncWithSecond("SendCareRemind", "0 30 8 * * *", func() {
			err1 := task.SendCareMsg()
			if err1 != nil {
				global.Logger.Error("定时发送植物养护提醒失败", zap.Error(err1))
			}
		}, "定时发送植物养护提醒", option...)
		if err != nil {
			fmt.Println("添加定时任务失败:", err)
		}
	}()
}
