package main

import (
	"fmt"
	"log/slog"

	// "github.com/gofiber/fiber/v2"
	// "github.com/gofiber/fiber/v2/middleware/cors"
	// "github.com/gofiber/swagger"

	"github.com/gofiber/contrib/swagger"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"

	//"github.com/gofiber/swagger"

	_ "code.wuban.net.cn/odysseus/twitter_syncer/docs"
	// docs are generated by Swag CLI, you have to import them.
	// replace with your own docs folder, usually "github.com/username/reponame/docs"
	//_ "github.com/gofiber/swagger/example/docs"
)

func main() {

	done := make(chan interface{})

	defer close(done)

	tasks, err := GetTasks()

	if err != nil {
		slog.Error(err.Error())
		return
	}

	go func() {

		for _, task := range tasks {
			fmt.Println(task.String())
			if err := Worker.AddJob(task); err != nil {
				slog.Error(err.Error())
			}
		}
	}()

	// taskIn = taskInStream

	app := fiber.New()

	app.Use(cors.New())

	//app.Static("/swagger/docs", "./docs")

	cfg := swagger.Config{
		BasePath: "/",
		FilePath: "./docs/swagger.yaml",
		Path:     "swagger",
		Title:    "Swagger API Docs",
	}

	app.Use(swagger.New(cfg))

	app.Post("/project", Project)
	app.Post("/task/add", TaskAdd)
	app.Post("/task/stop", TaskStop)
	app.Get("/verify/follower", VerifyFollower)
	app.Get("/verify/retweeter", VerifyRetweeter)
	//VerifyLike
	app.Get("/verify/like", VerifyLike)

	if err := app.Listen(":8001"); err != nil {
		slog.Error(err.Error())
	}
}

// type ReqDB struct {
// 	AddOrStop bool
// 	Project   string `json:"project"`
// 	TweetId   string `json:"tweet_id"`
// 	Like      bool   `json:"like"`
// 	Retweet   bool   `json:"retweet"`
// }
