package land

import (
	"time"

	"gorm.io/gorm"

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

type Land struct {
	ID          []byte     `gorm:"type:binary(16);primaryKey;column:id"`
	Name        string     `gorm:"type:varchar(128);not null;column:name"`
	Note        string     `gorm:"type:text;column:note"`
	LandISOCode string     `gorm:"type:varchar(8);not null;default:'';uniqueIndex:uq_lands_land_iso_code;column:land_iso_code"`
	BMDExportID *string    `gorm:"type:varchar(10);column:bmd_export_id"`
	SortKey     *int       `gorm:"column:sortkey"`
	IsActive    bool       `gorm:"type:tinyint(1);index;not null;default:1;column:is_active"`
	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"`
	DeletedBy   []byte     `gorm:"type:binary(16);column:deleted_by"`
}

func (Land) TableName() string { return "lands" }

func (l *Land) BeforeCreate(tx *gorm.DB) error {
	if len(l.ID) == 0 {
		l.ID = uuidv7.MustBytes()
	}
	return nil
}
