package com.rj.dto;

import lombok.Getter;

import java.util.Collections;
import java.util.List;

/**
 * 根据城市+地址做地理编码后，按半径周边搜索商家的结果。
 */
@Getter
public class NearbyMerchantSearchResult {

    private final int httpStatus;
    private final boolean success;
    private final String message;
    private final String centerLocation;
    private final List<NearbyMerchantItem> merchants;
    /** 高德返回的本次检索总条数（字符串），可能大于已拉取页数之和 */
    private final String totalCount;
    /**
     * 与 {@link com.rj.gaode.AllShopCollectorV5#parseAndPrint} 类似的商铺明细文本（含检索参数与每家店块）。
     */
    private final String detailedReport;
    /** 本次成功写入 {@code customer_management} 的条数（按 contact 匹配，含新增与更新） */
    private final Integer customerInsertedCount;

    private NearbyMerchantSearchResult(int httpStatus, boolean success, String message,
                                       String centerLocation, List<NearbyMerchantItem> merchants, String totalCount,
                                       String detailedReport, Integer customerInsertedCount) {
        this.httpStatus = httpStatus;
        this.success = success;
        this.message = message;
        this.centerLocation = centerLocation;
        this.merchants = merchants == null ? Collections.emptyList() : merchants;
        this.totalCount = totalCount;
        this.detailedReport = detailedReport;
        this.customerInsertedCount = customerInsertedCount;
    }

    public static NearbyMerchantSearchResult ok(String centerLocation, List<NearbyMerchantItem> merchants,
                                                String totalCount, String detailedReport, int customerInsertedCount) {
        return new NearbyMerchantSearchResult(200, true, "查询成功", centerLocation, merchants, totalCount,
                detailedReport, customerInsertedCount);
    }

    public static NearbyMerchantSearchResult badRequest(String message) {
        return new NearbyMerchantSearchResult(400, false, message, null, Collections.emptyList(), null, null, null);
    }

    public static NearbyMerchantSearchResult serverError(String message) {
        return new NearbyMerchantSearchResult(500, false, message, null, Collections.emptyList(), null, null, null);
    }
}
