package otherperson

import (
	"time"

	"gorm.io/gorm"

	"wucher/internal/shared/pkg/uuidv7"
)

type OtherPerson struct {
	ID          []byte `gorm:"type:binary(16);primaryKey;column:id"`
	Name        string `gorm:"type:varchar(191);column:name"`
	MobilePhone string `gorm:"type:varchar(64);column:mobile_phone"`
	Email       string `gorm:"type:varchar(191);column:email"`

	CreatedAt time.Time  `gorm:"column:created_at"`
	CreatedBy []byte     `gorm:"type:binary(16);column:created_by"`
	UpdatedAt time.Time  `gorm:"column:updated_at"`
	UpdatedBy []byte     `gorm:"type:binary(16);column:updated_by"`
	DeletedAt *time.Time `gorm:"column:deleted_at;index"`
	DeletedBy []byte     `gorm:"type:binary(16);column:deleted_by"`
}

func (OtherPerson) TableName() string { return "other_people" }

func (p *OtherPerson) BeforeCreate(_ *gorm.DB) error {
	if len(p.ID) == 0 {
		p.ID = uuidv7.MustBytes()
	}
	return nil
}
