package meet

import (
	"strings"
	"unicode/utf8"

	"github.com/ultisuite/ulti-backend/internal/api/apivalidate"
)

type transcriptRequest struct {
	RoomID            string   `json:"room_id"`
	OrganizerUserID   string   `json:"organizer_user_id"`
	OrganizerEmail    string   `json:"organizer_email"`
	ParticipantEmails []string `json:"participant_emails"`
	Transcript        string   `json:"transcript"`
	Mode              string   `json:"mode"`
	QueuedAudioURL    string   `json:"queued_audio_url"`
}

func validateTranscriptRequest(req *transcriptRequest) *apivalidate.ValidationError {
	room := strings.TrimSpace(req.RoomID)
	if room == "" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "room_id", Message: "required",
		})
	}
	if utf8.RuneCountInString(room) > 256 {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "room_id", Message: "too long",
		})
	}
	mode := strings.TrimSpace(req.Mode)
	if mode != "" && mode != "live" && mode != "queued" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "mode", Message: "must be live or queued",
		})
	}
	if strings.TrimSpace(req.Transcript) == "" && strings.TrimSpace(req.QueuedAudioURL) == "" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "transcript", Message: "transcript or queued_audio_url required",
		})
	}
	return nil
}
