package com.ecep.contract.service;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.vm.CompanyCustomerEvaluationFormFileViewModel;
import com.ecep.contract.vo.CompanyCustomerEvaluationFormFileVo;
import com.ecep.contract.vo.CompanyCustomerFileVo;

import java.util.List;

@Service
public class CompanyCustomerEvaluationFormFileService
        extends QueryService<CompanyCustomerEvaluationFormFileVo, CompanyCustomerEvaluationFormFileViewModel> {

    /**
     * 根据ID查找客户评估表文件
     */
    public CompanyCustomerEvaluationFormFileVo findById(Integer id) {
        return super.findById(id);
    }

    /**
     * 根据客户文件查找评估表文件
     */
    public CompanyCustomerEvaluationFormFileVo findByCustomerFile(CompanyCustomerFileVo customerFile) {
        return findByCustomerFile(customerFile.getId());
    }

    public CompanyCustomerEvaluationFormFileVo findByCustomerFile(Integer customerFileId) {
        List<CompanyCustomerEvaluationFormFileVo> page = findAll(ParamUtils.builder()
                .equals("customerFile", customerFileId)
                .build(), Pageable.ofSize(1))
                .getContent();
        if (page.isEmpty()) {
            return null;
        }
        return page.getFirst();
    }

    /**
     * 保存客户评估表文件
     */
    public CompanyCustomerEvaluationFormFileVo save(CompanyCustomerEvaluationFormFileVo formFile) {
        return super.save(formFile);
    }

}
