package com.sifang.modules.customer.Service;

import com.sifang.modules.customer.constant.CustomerEntryConstants;
import com.sifang.modules.customer.entity.CustomerEntry;
import com.sifang.modules.customer.form.AddEntryReq;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class CustomerEntryCheckService {

    public void checkHadCompleteTermination(CustomerEntry entry, AddEntryReq entryReq) {
        String creditStatus=entry.getCredit();
        if (StringUtil.isNotBlank(creditStatus) && StringUtil.equalsAny(creditStatus
                , CustomerEntryConstants.CREDIT_SUBMITTED,CustomerEntryConstants.CREDIT_APPROVE,CustomerEntryConstants.CREDIT_APPROVED)) {
            if (!Objects.equals(entry.getTenantName(),entryReq.getTenantName())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改业主姓名");
            }
            if (!Objects.equals(entryReq.getIdCode(),entry.getIdCode())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改身份证号");
            }
            if (!Objects.equals(entryReq.getGender(),entry.getGender())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改性别");
            }
            if (!Objects.equals(entryReq.getAge(),entry.getAge())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改年龄");
            }
            if (!Objects.equals(entry.getMobile(),entryReq.getMobile())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改联系方式");
            }
            if (!Objects.equals(entryReq.getProvince(),entry.getProvince())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改地址");
            }
            if (!Objects.equals(entryReq.getCity(),entry.getCity())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改地址");
            }
            if (!Objects.equals(entryReq.getArea(),entry.getArea())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改地址");
            }
            if (!Objects.equals(entryReq.getAddress(),entry.getAddress())) {
                throw new IllegalArgumentException("该电站有进行中或已完成的预审，不可修改地址");
            }
        }
    }
}
