package models

import (
	"time"

	"gorm.io/gorm"
)

type BaseModel struct {
	ID        ULID      `gorm:"primaryKey" json:"id" db:"id" `
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}

// BeforeCreate is a GORM hook that runs before creating a record
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
	if b.ID.IsZero() {
		b.ID = GenerateULID()
	}
	return nil
}
