package request

import (
	"campaign-pool-be/app/database/entity"
	"campaign-pool-be/utils/paginator"
)

// AI Chat Sessions Request DTOs
type AIChatSessionsQueryRequest struct {
	IsActive   *bool                 `json:"isActive"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type AIChatSessionsCreateRequest struct {
	SessionID string `json:"sessionId" validate:"required"`
	Title     string `json:"title" validate:"required,min=2,max=255"`
	AgentID   string `json:"agentId" validate:"required"`
}

func (req AIChatSessionsCreateRequest) ToEntity() *entity.AIChatSessions {
	return &entity.AIChatSessions{
		SessionID:    req.SessionID,
		AgentID:      req.AgentID,
		Title:        req.Title,
		MessageCount: 0,
		IsActive:     true,
	}
}

type AIChatSessionsUpdateRequest struct {
	Title    string `json:"title" validate:"required,min=2,max=255"`
	IsActive bool   `json:"isActive"`
}

func (req AIChatSessionsUpdateRequest) ToEntity() *entity.AIChatSessions {
	return &entity.AIChatSessions{
		Title:    req.Title,
		IsActive: req.IsActive,
	}
}

// AI Chat Messages Request DTOs
type AIChatMessagesQueryRequest struct {
	Pagination *paginator.Pagination `json:"pagination"`
}

type AIChatMessagesCreateRequest struct {
	SessionID   string `json:"sessionId" validate:"required"`
	MessageType string `json:"messageType" validate:"required,oneof=user assistant"`
	Content     string `json:"content" validate:"required,min=1"`
}

func (req AIChatMessagesCreateRequest) ToEntity() *entity.AIChatMessages {
	return &entity.AIChatMessages{
		SessionID:   req.SessionID,
		MessageType: req.MessageType,
		Content:     req.Content,
		IsActive:    true,
	}
}

type AIChatMessagesUpdateRequest struct {
	Content string `json:"content" validate:"required,min=1"`
}

func (req AIChatMessagesUpdateRequest) ToEntity() *entity.AIChatMessages {
	return &entity.AIChatMessages{
		Content: req.Content,
	}
}

type AIChatSessionsQueryRequestContext struct {
	IsActive string `json:"isActive"`
}

func (req AIChatSessionsQueryRequestContext) ToParamRequest() AIChatSessionsQueryRequest {
	var request AIChatSessionsQueryRequest

	if isActiveStr := req.IsActive; isActiveStr != "" {
		isActive := isActiveStr == "true"
		request.IsActive = &isActive
	}

	return request
}

type AIChatMessagesQueryRequestContext struct {
}

func (req AIChatMessagesQueryRequestContext) ToParamRequest() AIChatMessagesQueryRequest {
	var request AIChatMessagesQueryRequest

	return request
}

// AI Chat Logs Request DTOs
type AIChatLogsQueryRequest struct {
	LogType    *string               `json:"logType"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type AIChatLogsQueryRequestContext struct {
	LogType string `json:"logType"`
}

func (req AIChatLogsQueryRequestContext) ToParamRequest() AIChatLogsQueryRequest {
	var request AIChatLogsQueryRequest

	if logType := req.LogType; logType != "" {
		request.LogType = &logType
	}

	return request
}
