package param

import (
	"regexp"
	"strings"
)

const (
	id          = "benefactors.id"
	phoneNumber = "benefactors.phone_number"
	fullName    = "concat(benefactors.first_name, benefactors.last_name)"
)

var searchItems = []string{id, phoneNumber, fullName}

type SearchRequest struct {
	Query string `query:"search" example:"09123456789"`
}

type QuerySearch map[string]any

func (s *SearchRequest) GetSearch() *QuerySearch {
	searchParams := QuerySearch{}

	if s.Query != "" {
		s.Query = strings.TrimSpace(s.Query)
		re := regexp.MustCompile(`[\p{P}\p{S}]+`)
		s.Query = re.ReplaceAllString(s.Query, "")
		s.Query = strings.ReplaceAll(s.Query, " ", "")
		for _, val := range searchItems {
			searchParams[val] = s.Query
		}
	}
	return &searchParams
}
