package com.jeesharp.business.modules.food.service.settle;

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.finance.api.PaySettleBizOrderProvider;
import com.jeesharp.business.modules.finance.api.dto.PaySettleBizOrderSnapshot;
import com.jeesharp.business.modules.finance.paymentrecord.enums.PayRecordBizSceneEnum;
import com.jeesharp.business.modules.food.api.FoodFinanceReadApi;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 个人订餐业态 {@link PaySettleBizOrderProvider} 实现（委托 {@link FoodFinanceReadApi}）。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Service
@AllArgsConstructor
public class FoodMealPaySettleBizOrderProvider implements PaySettleBizOrderProvider {

    private final FoodFinanceReadApi foodFinanceReadApi;

    @Override
    public String bizScene() {
        return PayRecordBizSceneEnum.FOOD_MEAL_ORDER.getCode();
    }

    @Override
    public PaySettleBizOrderSnapshot getOrder(String bizOrderId) {
        return foodFinanceReadApi.getPersonalMealSnapshot(bizOrderId);
    }

    @Override
    public List<PaySettleBizOrderSnapshot> listSubOrdersForPay(String payBatchId, String bizOrderId) {
        String key = StrUtil.isNotBlank(payBatchId) ? payBatchId.trim() : bizOrderId;
        PaySettleBizOrderSnapshot single = getOrder(key);
        return single != null ? List.of(single) : Collections.emptyList();
    }

    @Override
    public String findFirstOrderIdByOrderNo(String orderNo) {
        return foodFinanceReadApi.findPersonalMealOrderIdByOrderNo(orderNo);
    }

    @Override
    public String findPayBatchIdByBatchNo(String batchNo) {
        return null;
    }

    @Override
    public Map<String, String> mapOrderNoByIds(Collection<String> bizOrderIds) {
        return foodFinanceReadApi.mapPersonalMealOrderNoByIds(bizOrderIds);
    }

    @Override
    public Map<String, String> mapBatchNoByIds(Collection<String> payBatchIds) {
        return Collections.emptyMap();
    }
}
