package request

import (
	"narasi-ahli-be/app/database/entity"
	"narasi-ahli-be/utils/paginator"
)

// Conversations Request DTOs
type ConversationsQueryRequest struct {
	Pagination *paginator.Pagination `json:"pagination"`
}

type ConversationsCreateRequest struct {
	Participant2ID uint `json:"participant2Id" validate:"required"`
}

func (req ConversationsCreateRequest) ToEntity() *entity.Conversations {
	return &entity.Conversations{
		Participant1ID: 0, // Will be set in service layer
		Participant2ID: req.Participant2ID,
	}
}

// Chat Messages Request DTOs
type ChatMessagesQueryRequest struct {
	ChatSessionID uint                  `json:"chatSessionId" validate:"required"`
	Pagination    *paginator.Pagination `json:"pagination"`
}

type ChatMessagesCreateRequest struct {
	ChatSessionID uint   `json:"chatSessionId" validate:"required"`
	Message       string `json:"message"`
	MessageType   string `json:"messageType" validate:"required,oneof=text image file audio"`
}

func (req ChatMessagesCreateRequest) ToEntity() *entity.ChatMessages {
	return &entity.ChatMessages{
		ChatSessionID: req.ChatSessionID,
		SenderID:      0, // Will be set in service layer
		Message:       req.Message,
		MessageType:   req.MessageType,
	}
}

type ChatMessagesFileUploadRequest struct {
	ChatSessionID uint   `json:"chatSessionId" validate:"required"`
	MessageType   string `json:"messageType" validate:"required,oneof=image file audio"`
	FileName      string `json:"fileName"`
	FileSize      int64  `json:"fileSize"`
}

func (req ChatMessagesFileUploadRequest) ToEntity(fileURL string) *entity.ChatMessages {
	return &entity.ChatMessages{
		ChatSessionID: req.ChatSessionID,
		SenderID:      0,  // Will be set in service layer
		Message:       "", // File messages might not have text content
		MessageType:   req.MessageType,
		// Note: FileURL, FileName, FileSize, IsRead fields are not available in the entity
		// These would need to be stored separately or the entity needs to be updated
	}
}

type ChatMessagesMarkReadRequest struct {
	MessageID uint `json:"messageId" validate:"required"`
}

type ConversationsQueryRequestContext struct {
	// No specific query parameters for conversations list
}

func (req ConversationsQueryRequestContext) ToParamRequest() ConversationsQueryRequest {
	return ConversationsQueryRequest{}
}

type ChatMessagesQueryRequestContext struct {
	ChatSessionID string `json:"chatSessionId"`
}

func (req ChatMessagesQueryRequestContext) ToParamRequest() ChatMessagesQueryRequest {
	var request ChatMessagesQueryRequest

	if chatSessionIDStr := req.ChatSessionID; chatSessionIDStr != "" {
		// Parse chat session ID from string to uint
		// This will be handled in the controller
	}

	return request
}
