package com.infoepoch.pms.agent.tool.union.care;

import com.infoepoch.pms.agent.common.utils.LogHelper;
import com.infoepoch.pms.agent.domain.care.log.CareTraceLogSupport;
import com.infoepoch.pms.agent.domain.care.model.PagedResult;
import com.infoepoch.pms.agent.domain.care.model.UserProfileSummary;
import com.infoepoch.pms.agent.tool.union.care.provider.CareBusinessDataProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户检索工具
 */
@Component
@RequiredArgsConstructor
public class UserSearchTool {

    private final CareBusinessDataProvider careBusinessDataProvider;

    /**
     * 按接口文档支持的筛选条件分页检索用户。
     */
    public PagedResult<UserProfileSummary> execute(String traceId,
                                                   String sessionId,
                                                   Map<String, Object> conditions,
                                                   int pageNo,
                                                   int pageSize) {
        LogHelper.info(this, CareTraceLogSupport.format(
                traceId,
                sessionId,
                "用户检索工具分发",
                "页码=%s，每页数量=%s，筛选条件=%s".formatted(
                        pageNo,
                        pageSize,
                        CareTraceLogSupport.safeConditionsSummary(conditions)
                )
        ));
        return careBusinessDataProvider.searchUsersByConditions(traceId, sessionId, conditions, pageNo, pageSize);
    }
}

