package logger

import (
	"testing"

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

func TestFieldConstants(t *testing.T) {
	assert.Equal(t, "request_id", FieldRequestID)
	assert.Equal(t, "provider_id", FieldProviderID)
	assert.Equal(t, "model_name", FieldModelName)
	assert.Equal(t, "method", FieldMethod)
	assert.Equal(t, "path", FieldPath)
	assert.Equal(t, "status", FieldStatusCode)
	assert.Equal(t, "latency", FieldLatency)
	assert.Equal(t, "client_ip", FieldClientIP)
	assert.Equal(t, "query", FieldQuery)
	assert.Equal(t, "body_size", FieldBodySize)
	assert.Equal(t, "sql", FieldSQL)
	assert.Equal(t, "rows_affected", FieldRows)
}

func TestFieldConstructors(t *testing.T) {
	t.Run("RequestID", func(t *testing.T) {
		field := RequestID("test-id")
		assert.Equal(t, FieldRequestID, field.Key)
		assert.Equal(t, "test-id", field.String)
	})

	t.Run("ProviderID", func(t *testing.T) {
		field := ProviderID("provider-123")
		assert.Equal(t, FieldProviderID, field.Key)
		assert.Equal(t, "provider-123", field.String)
	})

	t.Run("ModelName", func(t *testing.T) {
		field := ModelName("gpt-4")
		assert.Equal(t, FieldModelName, field.Key)
		assert.Equal(t, "gpt-4", field.String)
	})

	t.Run("Method", func(t *testing.T) {
		field := Method("POST")
		assert.Equal(t, FieldMethod, field.Key)
		assert.Equal(t, "POST", field.String)
	})

	t.Run("Path", func(t *testing.T) {
		field := Path("/v1/chat")
		assert.Equal(t, FieldPath, field.Key)
		assert.Equal(t, "/v1/chat", field.String)
	})

	t.Run("StatusCode", func(t *testing.T) {
		field := StatusCode(200)
		assert.Equal(t, FieldStatusCode, field.Key)
	})

	t.Run("Latency", func(t *testing.T) {
		field := Latency(int64(100))
		assert.Equal(t, FieldLatency, field.Key)
	})

	t.Run("ClientIP", func(t *testing.T) {
		field := ClientIP("127.0.0.1")
		assert.Equal(t, FieldClientIP, field.Key)
		assert.Equal(t, "127.0.0.1", field.String)
	})

	t.Run("Query", func(t *testing.T) {
		field := Query("key=value")
		assert.Equal(t, FieldQuery, field.Key)
		assert.Equal(t, "key=value", field.String)
	})

	t.Run("BodySize", func(t *testing.T) {
		field := BodySize(1024)
		assert.Equal(t, FieldBodySize, field.Key)
	})

	t.Run("SQL", func(t *testing.T) {
		field := SQL("SELECT * FROM users")
		assert.Equal(t, FieldSQL, field.Key)
		assert.Equal(t, "SELECT * FROM users", field.String)
	})

	t.Run("Rows", func(t *testing.T) {
		field := Rows(42)
		assert.Equal(t, FieldRows, field.Key)
		assert.Equal(t, int64(42), field.Integer)
	})

	t.Run("Err", func(t *testing.T) {
		err := assert.AnError
		field := Err(err)
		assert.Equal(t, "error", field.Key)
	})
}
