// models/review.go
package models

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

type Review struct {
	ID          uint           `json:"id" gorm:"primarykey"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
	
	Rating      int            `json:"rating" gorm:"not null;check:rating >= 1 AND rating <= 5"`
	Text        string         `json:"text" gorm:"type:text;not null"`
	Achievement string         `json:"achievement" gorm:"size:255"`
	Distance    string         `json:"distance" gorm:"size:50"`
	Improvement string         `json:"improvement" gorm:"size:100"`
	Trainings   int            `json:"trainings" gorm:"default:0"`
	Verified    bool           `json:"verified" gorm:"default:false"`
	
	// Связи
	AuthorID   uint           `json:"author_id" gorm:"not null"`
	Author     User           `json:"author" gorm:"foreignKey:AuthorID"`
}

// DTO для создания отзыва
type CreateReviewRequest struct {
	Rating      int    `json:"rating" validate:"required,min=1,max=5"`
	Text        string `json:"text" validate:"required,min=10,max=500"`
	Achievement string `json:"achievement" validate:"max=255"`
	Distance    string `json:"distance" validate:"max=50"`
	Improvement string `json:"improvement" validate:"max=100"`
	Trainings   int    `json:"trainings" validate:"min=0"`
}

// DTO для обновления отзыва
type UpdateReviewRequest struct {
	Rating      int    `json:"rating" validate:"omitempty,min=1,max=5"`
	Text        string `json:"text" validate:"omitempty,min=10,max=500"`
	Achievement string `json:"achievement" validate:"omitempty,max=255"`
	Distance    string `json:"distance" validate:"omitempty,max=50"`
	Improvement string `json:"improvement" validate:"omitempty,max=100"`
	Trainings   int    `json:"trainings" validate:"omitempty,min=0"`
}

// DTO для ответа с отзывом
type ReviewResponse struct {
	ID          uint      `json:"id"`
	CreatedAt   time.Time `json:"created_at"`
	Rating      int       `json:"rating"`
	Text        string    `json:"text"`
	Achievement string    `json:"achievement,omitempty"`
	Distance    string    `json:"distance,omitempty"`
	Improvement string    `json:"improvement,omitempty"`
	Trainings   int       `json:"trainings"`
	Verified    bool      `json:"verified"`
	Author      AuthorInfo `json:"author"`
}

// DTO для статистики отзывов
type ReviewsStatsResponse struct {
	TotalReviews  int     `json:"total_reviews"`
	AverageRating float64 `json:"average_rating"`
	SuccessStories int    `json:"success_stories"`
	RatingDistribution map[int]int `json:"rating_distribution"`
}