package com.loan.system.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.loan.system.domain.dto.CustomersOtherDTO;
import com.loan.system.domain.dto.LoanCaseDTO;
import com.loan.system.domain.entity.CustomersOther;
import com.loan.system.domain.vo.CustomersOtherVO;
import com.loan.system.repository.CustomerOtherRepository;
import com.loan.system.repository.CustomerRepository;
import com.loan.system.service.CustomerOtherService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerOtherServiceImpl implements CustomerOtherService {
    private final CustomerOtherRepository customerOtherRepository;

    CustomerOtherServiceImpl(CustomerOtherRepository customerOtherRepository, CustomerRepository customerRepository) {
        this.customerOtherRepository = customerOtherRepository;
    }

    @Override
    public CustomersOther addCustomers(CustomersOtherDTO customersOtherDTO) {
        CustomersOther customersOther = BeanUtil.copyProperties(customersOtherDTO, CustomersOther.class);
        customersOther.setIsDelete( false);
        return customerOtherRepository.save(customersOther);
    }

    @Override
    public CustomersOther findByIdNumber(String idNumber) {
        return customerOtherRepository.findByIdNumberAndIsDelete(idNumber,false);
    }

    @Override
    public void updateCustomerById(CustomersOtherDTO customers1, Long id) {
        customerOtherRepository.updateCustomerById(customers1,id);
    }

    @Override
    public CustomersOtherVO findById(Long custom1Id) {
        return BeanUtil.copyProperties(customerOtherRepository.findByCustomerOtherId(custom1Id,false),CustomersOtherVO.class);
    }

    @Override
    public List<CustomersOtherVO> findByCaseId(Long caseId) {
        return BeanUtil.copyToList(customerOtherRepository.findByCaseIdAndIsDelete(caseId,false),CustomersOtherVO.class);
    }

    @Override
    public void deleteAllByCaseId(Long caseId) {
        customerOtherRepository.deleteAllByCaseId(caseId);
    }

}
