package models

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestUserModel(t *testing.T) {
	// Test user model fields
	user := User{
		ID:        1,
		Username:  "testuser",
		Email:     "test@example.com",
		Password:  "hashedpassword",
		FirstName: "Test",
		LastName:  "User",
		Role:      "user",
		Active:    true,
	}

	// Verify user fields
	assert.Equal(t, uint(1), user.ID)
	assert.Equal(t, "testuser", user.Username)
	assert.Equal(t, "test@example.com", user.Email)
	assert.Equal(t, "hashedpassword", user.Password)
	assert.Equal(t, "Test", user.FirstName)
	assert.Equal(t, "User", user.LastName)
	assert.Equal(t, "user", user.Role)
	assert.True(t, user.Active)
}

func TestConversationModel(t *testing.T) {
	// Test conversation model fields
	conversation := Conversation{
		ID:         1,
		UserID:     1,
		Title:      "Test Conversation",
		Status:     "active",
		Department: "support",
		Priority:   "medium",
		Tags:       "test,sample",
	}

	// Verify conversation fields
	assert.Equal(t, uint(1), conversation.ID)
	assert.Equal(t, uint(1), conversation.UserID)
	assert.Equal(t, "Test Conversation", conversation.Title)
	assert.Equal(t, "active", conversation.Status)
	assert.Equal(t, "support", conversation.Department)
	assert.Equal(t, "medium", conversation.Priority)
	assert.Equal(t, "test,sample", conversation.Tags)
}

func TestMessageModel(t *testing.T) {
	// Test message model fields
	message := Message{
		ID:             1,
		ConversationID: 1,
		UserID:         1,
		Content:        "Test message content",
		Type:           "text",
		Status:         "sent",
		Sentiment:      0.5,
		IsAI:           false,
		AIModel:        "",
	}

	// Verify message fields
	assert.Equal(t, uint(1), message.ID)
	assert.Equal(t, uint(1), message.ConversationID)
	assert.Equal(t, uint(1), message.UserID)
	assert.Equal(t, "Test message content", message.Content)
	assert.Equal(t, "text", message.Type)
	assert.Equal(t, "sent", message.Status)
	assert.Equal(t, 0.5, message.Sentiment)
	assert.False(t, message.IsAI)
	assert.Equal(t, "", message.AIModel)
}

func TestKnowledgeModel(t *testing.T) {
	// Test knowledge model fields
	knowledge := KnowledgeBase{
		ID:         1,
		Question:   "Test Question",
		Answer:     "Test knowledge content",
		Category:   "general",
		Tags:       "test,sample",
		Priority:   1,
		ViewCount:  10,
		Helpful:    5,
		NotHelpful: 2,
		Active:     true,
		CreatedBy:  1,
		UpdatedBy:  1,
	}

	// Verify knowledge fields
	assert.Equal(t, uint(1), knowledge.ID)
	assert.Equal(t, "Test Question", knowledge.Question)
	assert.Equal(t, "Test knowledge content", knowledge.Answer)
	assert.Equal(t, "general", knowledge.Category)
	assert.Equal(t, "test,sample", knowledge.Tags)
	assert.Equal(t, 1, knowledge.Priority)
	assert.Equal(t, 10, knowledge.ViewCount)
	assert.Equal(t, 5, knowledge.Helpful)
	assert.Equal(t, 2, knowledge.NotHelpful)
	assert.True(t, knowledge.Active)
	assert.Equal(t, uint(1), knowledge.CreatedBy)
	assert.Equal(t, uint(1), knowledge.UpdatedBy)
}

func TestAIModel(t *testing.T) {
	// Test AI model fields
	aiModel := AIModel{
		ID:          1,
		Name:        "Test AI Model",
		Type:        "openai",
		Endpoint:    "https://api.openai.com/v1/chat/completions",
		APIKey:      "test-api-key",
		Model:       "gpt-4",
		MaxTokens:   4000,
		Temperature: 0.7,
		TopP:        1.0,
		Active:      true,
		Priority:    1,
		Description: "Test AI model description",
	}

	// Verify AI model fields
	assert.Equal(t, uint(1), aiModel.ID)
	assert.Equal(t, "Test AI Model", aiModel.Name)
	assert.Equal(t, "openai", aiModel.Type)
	assert.Equal(t, "https://api.openai.com/v1/chat/completions", aiModel.Endpoint)
	assert.Equal(t, "test-api-key", aiModel.APIKey)
	assert.Equal(t, "gpt-4", aiModel.Model)
	assert.Equal(t, 4000, aiModel.MaxTokens)
	assert.Equal(t, 0.7, aiModel.Temperature)
	assert.Equal(t, 1.0, aiModel.TopP)
	assert.True(t, aiModel.Active)
	assert.Equal(t, 1, aiModel.Priority)
	assert.Equal(t, "Test AI model description", aiModel.Description)
}
