package entities

import (
	"github.com/google/uuid"
	"strconv"
	"time"

	"gorm.io/gorm"
)

type ID struct {
	ID int64 `gorm:"primaryKey"`
}

func IDFromInt64(val int64) ID {
	return ID{
		ID: val,
	}
}

func (id ID) ToInt64() int64 {
	return int64(id.ID)
}

func (id ID) ToString() string {
	return strconv.FormatInt(id.ID, 10)
}

type AuditTime struct {
	CreatedAt time.Time
	UpdatedAt time.Time
}

type SoftDelete struct {
	DeletedAt gorm.DeletedAt
}

type BaseEntity struct {
	ID
	AuditTime
	SoftDelete
}

type BaseUuidEntity struct {
	ID uuid.UUID `gorm:"default:gen_random_uuid()"`

	AuditTime
	SoftDelete
}

const (
	LanguageEN = "en"
	LanguageTH = "th"
	LanguageCN = "cn"
	LanguageMY = "my"
	LanguageSG = "sg"
	LanguagePH = "ph"
	LanguageVN = "vn"
)

const (
	CountryIDSG = 1
	CountryIDMY = 2
	CountryIDPH = 3
	CountryIDTH = 4
)

var AcceptLanguageMap = map[string]string{
	"en":    LanguageEN,
	"en-us": LanguageEN,
	"en-ph": LanguageEN,
	"th":    LanguageTH,
	"th-th": LanguageTH,
	"tha":   LanguageTH,
	"zh":    LanguageCN,
	"zh-cn": LanguageCN,
	"my":    LanguageMY,
	"mys":   LanguageMY,
	"ms-my": LanguageMY,
	"sg":    LanguageSG,
	"zh-sg": LanguageSG,
	"ph":    LanguagePH,
	"vi":    LanguageVN,
	"vi-vn": LanguageVN,
}

var LanguageCountryIDMap = map[string]int64{
	LanguageSG: CountryIDSG,
	LanguageMY: CountryIDMY,
	LanguagePH: CountryIDPH,
	LanguageTH: CountryIDTH,
}

var RegionCurrencyMap = map[string]string{
	"SG": "SGD",
	"TH": "THB",
	"PH": "PHP",
	"MY": "MYR",
}
