package meet

import (
	"strings"
	"unicode/utf8"

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

const maxRequestBody = 8 << 10

type createRoomRequest struct {
	Name string `json:"name"`
}

func validateCreateRoom(req *createRoomRequest) *apivalidate.ValidationError {
	name := strings.TrimSpace(req.Name)
	if name == "" {
		return nil
	}
	if utf8.RuneCountInString(name) > 128 {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "name", Message: "too long",
		})
	}
	if strings.ContainsAny(name, "/\r\n") {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "name", Message: "invalid characters",
		})
	}
	return nil
}

func validateRoomID(roomID string) *apivalidate.ValidationError {
	if strings.TrimSpace(roomID) == "" {
		return apivalidate.NewValidationError(apivalidate.FieldDetail{
			Field: "room_id", Message: "required",
		})
	}
	return nil
}
