package com.gxwebsoft.house.ai;

import cn.hutool.core.util.StrUtil;
import com.gxwebsoft.house.entity.HouseAiIntent;
import org.springframework.stereotype.Component;

/**
 * AI找房追问建议器，负责在需求过少时先问关键问题。
 */
@Component
public class HouseAiClarificationAdvisor {

    public String buildBlockingQuestion(HouseAiIntent intent) {
        if (intent == null) {
            return "您可以告诉我预算、面积和区域，我再帮您筛选合适房源。";
        }
        if (!requiresHouseSearch(intent)) {
            return "我可以继续帮您找房。您先告诉我预算、面积和区域中的任意两项，我会按条件筛选。";
        }
        if (!hasHouseCondition(intent)) {
            return "您想找哪个区域或商圈？预算和面积大概是多少？";
        }
        return "";
    }

    public boolean requiresHouseSearch(HouseAiIntent intent) {
        return hasHouseCondition(intent) || "mixed".equals(intent.getIntentType()) || "house".equals(intent.getIntentType());
    }

    private boolean hasHouseCondition(HouseAiIntent intent) {
        if (intent == null) {
            return false;
        }
        return intent.getExtentMin() != null
            || intent.getExtentMax() != null
            || intent.getFloorMin() != null
            || intent.getFloorMax() != null
            || intent.getMonthlyRentMin() != null
            || intent.getMonthlyRentMax() != null
            || intent.getSalePriceMin() != null
            || intent.getSalePriceMax() != null
            || intent.getTotalPriceMin() != null
            || intent.getTotalPriceMax() != null
            || StrUtil.isNotBlank(intent.getCityKeyword())
            || StrUtil.isNotBlank(intent.getRegionKeyword())
            || StrUtil.isNotBlank(intent.getDecorationType())
            || StrUtil.isNotBlank(intent.getSupportingKeyword())
            || StrUtil.isNotBlank(intent.getToward())
            || StrUtil.isNotBlank(intent.getHouseType());
    }
}
