package kok

import (
	"crypto/hmac"
	"crypto/sha256"
	"fmt"
	fiko_mongo "server/sistem/fikoyt_mongo"
	"time"

	"github.com/gofiber/contrib/monitor"
	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/middleware/session"
	"github.com/gofiber/fiber/v3/middleware/static"
)

func KokRouting(app *fiber.App) {

	app.Use("/", static.New("./statik"))

	app.Get("/", func(c fiber.Ctx) error {
		// panic("asdasda")
		// user := c.Locals("FikoYT").(fiber.Map)
		session := c.Locals("session").(*session.Session)

		s, err := fiko_mongo.GetSessionData(session, "test")
		if err != nil {

		}

		return c.Status(200).JSON(s)
	})
	///
	app.Get("/metrics", monitor.New(monitor.Config{Title: "FikoYT Metrikler"}))

	///
	app.Post("/fapi/fikoyt.com.FikoYT.sistem.Uye.Ol", fikoyt_sistem_uye_ol)

	app.Get("/fikoyt.com.FikoYT.sistem.dosyalar.:id.resim", fikoyt_sistem_dosyalar_id_resim)
}

func epostaOnayKoduFonksiyonu(ad, soyad, kullaniciAdi string) string {
	// Bugün tarihine 1 gün ekleyelim
	a := time.Now().Add(24 * time.Hour)

	// Verileri birleştir
	dataToHash := ad + " " + soyad + kullaniciAdi + a.String()

	// Gizli anahtar (bu anahtar sizin tarafınızdan belirlenmeli)
	secretKey := []byte("FikoYT+1299")

	// HMAC-SHA256 kullanarak veri hashing
	hash := hmac.New(sha256.New, secretKey)
	hash.Write([]byte(dataToHash))
	hashedCode := hash.Sum(nil)

	// Hash kodu hex formatında döndürüyoruz
	return fmt.Sprintf("%x", hashedCode)
}

func parolaSifrele(parola string) string {
	// Verileri birleştir
	dataToHash := parola

	// Gizli anahtar (bu anahtar sizin tarafınızdan belirlenmeli)
	secretKey := []byte("FikoYT+1299")

	// HMAC-SHA256 kullanarak veri hashing
	hash := hmac.New(sha256.New, secretKey)
	hash.Write([]byte(dataToHash))
	hashedCode := hash.Sum(nil)

	// Hash kodu hex formatında döndürüyoruz
	return fmt.Sprintf("%x", hashedCode)
}

// HMAC ile Parola Doğrulama
func ParolaDogrula(parola, storedHash string) bool {
	// Gizli anahtar (bunu gerçek bir uygulamada gizli tutun)
	secretKey := []byte("FikoYT+1299")

	// Parolayı HMAC-SHA256 ile hash'le
	hash := hmac.New(sha256.New, secretKey)
	hash.Write([]byte(parola))
	calculatedHash := fmt.Sprintf("%x", hash.Sum(nil))

	// Hash'leri karşılaştır
	return storedHash == calculatedHash
}
