package dto

import (
	"api_es/internal/models"
	"time"
)

// RegisterRequest - запрос на регистрацию
type RegisterRequest struct {
	Email     string `json:"email" validate:"required,email"`
	Password  string `json:"password" validate:"required,min=6"`
	FullName  string `json:"full_name" validate:"required"`
	FirstName string `json:"first_name" validate:"required"`
	LastName  string `json:"last_name" validate:"required"`
	Phone     string `json:"phone"`
	City      string `json:"city"`
}

// LoginRequest - запрос на вход
type LoginRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
}

// UpdateUserRequest - запрос на обновление пользователя
type UpdateUserRequest struct {
	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"`
}

// UserResponse - ответ с данными пользователя
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"`
}

// AuthResponse - ответ с токеном
type AuthResponse struct {
	Token string       `json:"token"`
	User  UserResponse `json:"user"`
}

// ToUserResponse преобразует модель в DTO
func ToUserResponse(user *models.User) UserResponse {
	return UserResponse{
		ID:                user.ID,
		Email:             user.Email,
		FullName:          user.FullName,
		FirstName:         user.FirstName,
		LastName:          user.LastName,
		Phone:             user.Phone,
		City:              user.City,
		OrganizationForm:  user.OrganizationForm,
		OrganizationName:  user.OrganizationName,
		OrganizationShort: user.OrganizationShort,
		INN:               user.INN,
		PersonalINN:       user.PersonalINN,
		IsActive:          user.IsActive,
		IsVerified:        user.IsVerified,
		Role:              user.Role,
		CreatedAt:         user.CreatedAt,
	}
}

// dto/auth.go (добавляем если нужно)
type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token" validate:"required"`
}
