// Package models provides ...
package models

import (
	"gorm.io/datatypes"
	"gorm.io/gorm"
)

type Card struct {
	gorm.Model
	UserID     uint
	User       User
	Front      string `json:"front" binding:"required"`
	Back       string `json:"back" binding:"required"`
	Hint       string `json:"hint"`
	CardDeckID uint   `json:"deck_id" binding:"required"`
	CardDeck   CardDeck
	PhaseID    uint
	Phase      Phase
	NextTest   datatypes.Date
}

type CardDto struct {
	ID         uint   `json:"id"`
	Front      string `json:"front" binding:"required"`
	Back       string `json:"back" binding:"required"`
	Hint       string `json:"hint"`
	CardDeckID uint   `json:"deck_id" binding:"required"`
}

func (c Card) ToDto() CardDto {
	return CardDto{c.ID, c.Front, c.Back, c.Hint, c.CardDeckID}
}
func (c CardDto) ToDbo() Card {
	return Card{Front: c.Front, Back: c.Back, Hint: c.Hint, CardDeckID: c.CardDeckID}
}

func (c *Card) BeforeCreate(tx *gorm.DB) (err error) {
	c.PhaseID = phaseOneID
	return
}
