package models

import (
	"gorm.io/gorm"
	"time"
)

type User struct {
	ID        uint           `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	// Основная информация
	Email        string `gorm:"uniqueIndex;not null" json:"email"`
	PasswordHash string `gorm:"not null" json:"-"`
	FullName     string `gorm:"not null;default:'Unknown'" json:"full_name"`
	FirstName    string `gorm:"not null;default:'FirstName'" json:"first_name"`
	LastName     string `gorm:"not null;default:'LastName'" json:"last_name"`
	Phone        string `json:"phone"`
	City         string `json:"city"`

	// Бизнес информация (для владельцев объектов)
	OrganizationForm  string `json:"organization_form"` // ИП, ООО и т.д.
	OrganizationName  string `json:"organization_name"`
	OrganizationShort string `json:"organization_short"`
	INN               string `json:"inn"`          // ИНН организации
	PersonalINN       string `json:"personal_inn"` // Личный ИНН

	// Статус
	IsActive   bool   `gorm:"default:true" json:"is_active"`
	IsVerified bool   `gorm:"default:false" json:"is_verified"`
	Role       string `gorm:"default:user" json:"role"` // user, admin, moderator

	// Связи
	Objects []Object `gorm:"foreignKey:OwnerID" json:"-"`
	Reviews []Review `gorm:"foreignKey:AuthorID" json:"-"`
}

// UserStats представляет статистику пользователя
type UserStats struct {
	UserID            uint `gorm:"primaryKey" json:"user_id"`
	TotalObjects      int  `gorm:"default:0" json:"total_objects"`
	ActiveObjects     int  `gorm:"default:0" json:"active_objects"`
	ModerationObjects int  `gorm:"default:0" json:"moderation_objects"`
	TotalReviews      int  `gorm:"default:0" json:"total_reviews"`
}

// UserResponse - структура для ответа API (без чувствительных данных)
type UserResponse struct {
	ID                uint      `json:"id"`
	Email             string    `json:"email"`
	FullName          string    `json:"full_name"`
	FirstName         string    `json:"first_name"`
	LastName          string    `json:"last_name"`
	Phone             string    `json:"phone"`
	City              string    `json:"city"`
	OrganizationForm  string    `json:"organization_form"`
	OrganizationName  string    `json:"organization_name"`
	OrganizationShort string    `json:"organization_short"`
	INN               string    `json:"inn"`
	PersonalINN       string    `json:"personal_inn"`
	IsActive          bool      `json:"is_active"`
	IsVerified        bool      `json:"is_verified"`
	Role              string    `json:"role"`
	CreatedAt         time.Time `json:"created_at"`
	Stats             UserStats `json:"stats,omitempty"`
}
