package org.example.mybatisplus.model.auto;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.example.mybatisplus.model.auto.EntRiskQxbEmployeesInfo.ItemsInner;
import org.example.mybatisplus.module.AuditResult;
import org.example.mybatisplus.module.BasicInfo;
import org.example.mybatisplus.module.vo.SuperiorAuthority;

import lombok.Builder;
import lombok.Getter;

/**
 * 企业风险信息-基于启信宝bo
 *
 * @author snows
 * @date 2024/10/14
 */
@Getter
@Builder
public class CmsEnterpriseRiskQxbInfoBO {

    /**
     * 基本信息
     */
    private EntRiskQxbBaseInfo baseInfo;

    /**
     * 工商年报信息
     */
    private EntRiskQxbReportListInfo reportListInfo;

    /**
     * 纳税人类型信息
     */
    private EntRiskQxbTaxpayerListInfo taxpayerListInfo;

    /**
     * 社保信息
     */
    private EntRiskQxbSocialSecurityInfo socialSecurityInfo;

    /**
     * 行政处罚信息
     */
    private EntRiskQxbAdminPunishInfo adminPunishInfo;

    /**
     * 经营异常信息
     */
    private EntRiskQxbAbnormalsInfo abnormalsInfo;

    /**
     * 重大税收违法信息
     */
    private EntRiskQxbTaxCaseInfo taxCaseInfo;

    /**
     * 严重违法信息
     */
    private EntRiskQxbSeriousIllegalInfo seriousIllegalInfo;

    /**
     * 主要人员信息
     */
    private EntRiskQxbEmployeesInfo employeesInfo;

    /**
     * 失信被执行企业信息
     */
    private EntRiskQxbExecutionListInfo executionListInfo;

    /**
     * 52.1-纳税A级
     */
    private EntRiskQxbCreditGradeInfo creditGradeInfo;

    public BasicInfo fillBasicInfoVO (BasicInfo info) {
        info.setInstitutionName(baseInfo.getName());
        info.setEstablishmentDate(baseInfo.getCheckDate());
        info.setRegistrationExpiryDate(String.format("%s至%s", baseInfo.getTermStart(), baseInfo.getTermEnd()));
        info.setPublicActivityScope(baseInfo.getScope());
        info.setNetAsset(baseInfo.getActualCapi());
        info.setLegalRepresentative(baseInfo.getOperName());
        Optional<ItemsInner> optionalSecretory = employeesInfo.getItems()
            .stream().filter(item -> item.getTitle().equals("秘书长")).findFirst();
        info.setSecretaryGeneral(optionalSecretory.isPresent() ? optionalSecretory.get().getName() : "-");
        Optional<ItemsInner> optionalchairman = employeesInfo.getItems()
            .stream().filter(item -> item.getTitle().equals("理事长")).findFirst();
        info.setChairman(optionalchairman.isPresent() ? optionalchairman.get().getName() : "-");
        info.setNumberOfDirectors(employeesInfo.getItems()
            .stream().filter(item -> item.getTitle().contains("理事")).count());
        info.setFoundationLocation(baseInfo.getAddress());
        List list=new ArrayList<>();
        list.add(new SuperiorAuthority(baseInfo.getBelongOrg(), "-"));
        info.setSuperiorAuthority(list);
        info.setRenzcode(baseInfo.getRegNo());
        info.setValidate(String.format("%s至%s", baseInfo.getTermStart(), baseInfo.getTermEnd()));
        return info;
    }

    public void fillAuditResultVO(AuditResult auditResult) {
    }
}
