package models

import (
	"time"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	UserName         string          `json:"username" gorm:"type:varchar(255)"`
	Email            string          `gorm:"uniqueIndex;not null;type:varchar(255)" json:"email"`
	Password         string          `json:"-" gorm:"type:varchar(255)"`          // Password shouldn't be returned in JSON
	EmailVerified    *bool           `gorm:"default:false" json:"email_verified"` // default false for email/password registration
	EmailVerifyToken string          `gorm:"index;type:varchar(255)" json:"-"`
	EmailVerifiedAt  *time.Time      `json:"email_verified_at,omitempty"`
	IsAdmin          *bool           `gorm:"default:false" json:"is_admin"`
	SocialAccounts   []SocialAccount `gorm:"foreignKey:UserID" json:"social_accounts,omitempty"`
	Profile          []Profile       `gorm:"foreignKey:UserID" json:"profiles,omitempty"`
}

// IsEmailVerified Email Veriyf i False Döndürüyor
func (u *User) IsEmailVerified() bool {
	if u.EmailVerified == nil {
		return false
	}
	return *u.EmailVerified
}

// SocialAccount model structure
type SocialAccount struct {
	gorm.Model
	UserID     uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
	Provider   string `gorm:"type:varchar(32);not null;uniqueIndex:idx_social_provider_identity" json:"provider"` // google, github
	ProviderID string `gorm:"type:varchar(191);not null;uniqueIndex:idx_social_provider_identity" json:"provider_id"`
	Email      string `json:"email" gorm:"type:varchar(255)"`
	Name       string `json:"name,omitempty" gorm:"type:varchar(255)"`       // Full name from provider
	AvatarURL  string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider

}
type Profile struct {
	gorm.Model
	UserID    uint64 `gorm:"type:bigint unsigned;not null;index" json:"user_id"`
	AvatarURL string `json:"avatar_url,omitempty" gorm:"type:varchar(255)"` // Avatar URL from provider
	FirstName string `json:"first_name" gorm:"type:varchar(255)"`           // Full name from provider
	LastName  string `json:"last_name" gorm:"type:varchar(255)"`            // Full name from provider

}
