package com.izouma.dingdong.service.merchant;

import cn.hutool.core.bean.BeanUtil;
import com.izouma.dingdong.domain.User;
import com.izouma.dingdong.domain.merchant.Merchant;
import com.izouma.dingdong.domain.merchant.MerchantComplaint;
import com.izouma.dingdong.dto.MerchantComplaintDTO;
import com.izouma.dingdong.exception.BusinessException;
import com.izouma.dingdong.repo.UserRepo;
import com.izouma.dingdong.repo.merchant.MerchantComplaintRepo;
import com.izouma.dingdong.repo.merchant.MerchantRepo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class MerchantComplaintService {

    private MerchantComplaintRepo merchantComplaintRepo;
    private MerchantRepo          merchantRepo;
    private UserRepo              userRepo;

    public MerchantComplaintDTO toDto(MerchantComplaint complaint) {
        MerchantComplaintDTO dto = new MerchantComplaintDTO();
        dto.setMerchantComplaint(complaint);
        User user = userRepo.findById(complaint.getUserId()).orElseThrow(new BusinessException("无记录"));
        dto.setUserNickname(user.getNickname());
        Merchant merchant = merchantRepo.findById(complaint.getMerchantId()).orElseThrow(new BusinessException("无记录"));
        dto.setMerShowName(merchant.getShowName());

        return dto;
    }
}
