package com.loan.system.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.loan.system.domain.entity.Customer;
import com.loan.system.domain.vo.CustomerVO;
import com.loan.system.repository.CustomerRepository;
import com.loan.system.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerRepository customerRepository;

    @Override
    public Customer addCustomer(Customer customer) {
        // 可以在这里添加业务逻辑，如校验等
        return customerRepository.save(customer);
    }

    @Override
    public void updateMarriedStatusById(Long customerId, String marriedStatus) {
        customerRepository.updateMarriedStatusById(customerId,marriedStatus);
    }

    @Override
    public CustomerVO findByCustomerIdAndIsDelete(Long customerId, Boolean isDelete) {

        return BeanUtil.copyProperties(customerRepository.findByCustomerId(customerId,isDelete),CustomerVO.class);
    }

    @Override
    public List<CustomerVO> getAllCustomers(boolean b) {
        return BeanUtil.copyToList(customerRepository.findByIsDelete(b),CustomerVO.class);
    }

    @Override
    public CustomerVO getCustomerByKey(String key, boolean b) {
        return BeanUtil.copyProperties(customerRepository.findByKey(key,b),CustomerVO.class);
    }

    @Override
    public CustomerVO getCustomerByMobile(String tel) {
        return  BeanUtil.copyProperties(customerRepository.findByMobile(tel, false),CustomerVO.class);
    }

    @Override
    public boolean existsBymobileAndIsDelete(String phoneNumber){
        return customerRepository.existsByMobileAndIsDelete(phoneNumber,false);
    }
    @Override
    public Customer findBymobileAndIsDelete(String phoneNumber){
        return customerRepository.findByMobile(phoneNumber,false);
    }
    @Override
    public Customer findByIdAndIsDelete(Long id){
        return customerRepository.findByIdAndIsDelete(id,false);
    }
}