package mapping

import (
	"log"
	"time"

	"gorm.io/datatypes"

	api "github.com/moustachioed/dash/backend/dashapi"
	db "github.com/moustachioed/dash/backend/database/models"
)

type MapperImpl struct{}

func NewMapperImpl() Mapper {
	return MapperImpl{}
}

func (mapper MapperImpl) JournalApiToDb(apimodel api.JournalEntry) db.Journal {
	date, err := time.Parse("2006-01-02", apimodel.Date)
	if err != nil {
		log.Printf("[ERROR] Could not parse date `%s`", apimodel.Date)
	}

	dbmodel := db.Journal{
		Date: datatypes.Date(date),
		// Thankful: datatypes.JSON([]byte(api.Thankful)),
	}

	return dbmodel
}

func (mapper MapperImpl) JournalDbToApi(db.Journal) api.JournalEntry {
	apimodel := api.JournalEntry{}

	return apimodel
}
