package main

import (
	logger "git.site.quack-lab.dev/dave/cylogger"
)

var whitelistedAchievements = map[string]bool{
	"15":    true,
	"958":   true,
	"1276":  true,
	"2088":  true,
	"2151":  true,
	"5466":  true,
	"5759":  true,
	"6470":  true,
	"6763":  true,
	"7392":  true,
	"7393":  true,
	"7394":  true,
	"7958":  true,
	"8939":  true,
	"8992":  true,
	"9048":  true,
	"94103": true,
	"10059": true,
	"10079": true,
	"10278": true,
	"10657": true,
	"10672": true,
	"10684": true,
	"10688": true,
	"10689": true,
	"10692": true,
	"10693": true,
	"10698": true,
	"10790": true,
	"10875": true,
	"11124": true,
	"11126": true,
	"11127": true,
	"11128": true,
	"11157": true,
	"11164": true,
	"11188": true,
	"11189": true,
	"11190": true,
	"11446": true,
	"11473": true,
	"11610": true,
	"11674": true,
	"11992": true,
	"11993": true,
	"11994": true,
	"11995": true,
	"11996": true,
	"11997": true,
	"11998": true,
	"11999": true,
	"12000": true,
	"12001": true,
	"12026": true,
	"12074": true,
	"12445": true,
	"12447": true,
	"12448": true,
}

func Save(message *NSQMessage, db *DB) error {
	_, ok := whitelistedAchievements[message.ID]
	if !ok {
		logger.Debug("Received message for non-whitelisted achievement %s", message.ID)
		return nil
	}

	_, err := db.writeConn.Exec("INSERT OR IGNORE INTO achievements (name, id, date, completed) VALUES (?, ?, ?, ?)",
		message.Name, message.ID, message.Date, message.Completed)
	if err != nil {
		logger.Error("Error inserting into database: %v", err)
		return err
	}

	return nil
}
