package shop.alien.lawyer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import shop.alien.entity.result.R;
import shop.alien.entity.store.LawyerUser;
import shop.alien.lawyer.service.AlipayZftCreateRecordService;
import shop.alien.mapper.LawyerUserMapper;

/**
 * 支付宝直付通进件创建记录（按律所名称关联律师用户二级商户账号）
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AlipayZftCreateRecordServiceImpl implements AlipayZftCreateRecordService {

    private final LawyerUserMapper lawyerUserMapper;

    @Override
    public R<Boolean> existsByMerchantName(String merchantName) {
        if (!StringUtils.hasText(merchantName)) {
            return R.data(false);
        }
        LambdaQueryWrapper<LawyerUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LawyerUser::getLawFirm, merchantName.trim())
                .eq(LawyerUser::getDeleteFlag, 0)
                .isNotNull(LawyerUser::getZfbSecondaryMerchantAccount)
                .ne(LawyerUser::getZfbSecondaryMerchantAccount, "");
        long n = lawyerUserMapper.selectCount(wrapper);
        return R.data(n > 0);
    }
}
