package cn.com.poc.ai_software_copyright.convert;

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

import cn.com.poc.ai_software_copyright.contant.AiSoftWareCopyRightEnum;
import cn.com.poc.ai_software_copyright.dto.SoftwareCopyRightFilesDto;
import cn.com.poc.ai_software_copyright.model.BizSoftwareCopyrightDocRecordModel;
import cn.com.poc.ai_software_copyright.entity.BizSoftwareCopyrightDocRecordEntity;
import org.apache.commons.lang3.StringUtils;


public class BizSoftwareCopyrightDocRecordConvert {

    public static BizSoftwareCopyrightDocRecordEntity modelToEntity(BizSoftwareCopyrightDocRecordModel model) {
        BizSoftwareCopyrightDocRecordEntity entity = new BizSoftwareCopyrightDocRecordEntity();
        entity.setId(model.getId());
        entity.setRelationId(model.getRelationId());
        entity.setInformation(model.getInformation());
        entity.setPcOperatingManual(model.getPcOperatingManual());
        entity.setPhOperatingManual(model.getPhOperatingManual());
        entity.setSourceCode(model.getSourceCode());
        entity.setAggregationUrl(model.getAggregationUrl());
        entity.setIsDeleted(model.getIsDeleted());
        entity.setCreator(model.getCreator());
        entity.setCreatedTime(model.getCreatedTime());
        entity.setModifier(model.getModifier());
        entity.setModifiedTime(model.getModifiedTime());
        entity.setSysVersion(model.getSysVersion());
        return entity;
    }

    public static BizSoftwareCopyrightDocRecordModel entityToModel(BizSoftwareCopyrightDocRecordEntity entity) {
        BizSoftwareCopyrightDocRecordModel model = new BizSoftwareCopyrightDocRecordModel();
        model.setId(entity.getId());
        model.setRelationId(entity.getRelationId());
        model.setInformation(entity.getInformation());
        model.setPcOperatingManual(entity.getPcOperatingManual());
        model.setPhOperatingManual(entity.getPhOperatingManual());
        model.setSourceCode(entity.getSourceCode());
        model.setAggregationUrl(entity.getAggregationUrl());
        model.setIsDeleted(entity.getIsDeleted());
        model.setCreator(entity.getCreator());
        model.setCreatedTime(entity.getCreatedTime());
        model.setModifier(entity.getModifier());
        model.setModifiedTime(entity.getModifiedTime());
        model.setSysVersion(entity.getSysVersion());
        return model;
    }

    public static List<SoftwareCopyRightFilesDto> entityToDto(BizSoftwareCopyrightDocRecordEntity recordEntity) {
        List<SoftwareCopyRightFilesDto> dtos = new ArrayList<>();

        String information = recordEntity.getInformation();
        String pcOperatingManual = recordEntity.getPcOperatingManual();
        String phOperatingManual = recordEntity.getPhOperatingManual();
        String sourceCode = recordEntity.getSourceCode();
        if (StringUtils.isNotBlank(information)) {
            SoftwareCopyRightFilesDto dto = new SoftwareCopyRightFilesDto();
            dto.setType(AiSoftWareCopyRightEnum.DOC_TYPE.information.name());
            dto.setFileUrl(information);
            dtos.add(dto);
        }
        if (StringUtils.isNotBlank(sourceCode)) {
            SoftwareCopyRightFilesDto dto = new SoftwareCopyRightFilesDto();
            dto.setType(AiSoftWareCopyRightEnum.DOC_TYPE.source_code.name());
            dto.setFileUrl(sourceCode);
            dtos.add(dto);
        }
        if (StringUtils.isNotBlank(pcOperatingManual)) {
            SoftwareCopyRightFilesDto dto = new SoftwareCopyRightFilesDto();
            dto.setType(AiSoftWareCopyRightEnum.DOC_TYPE.pc_operating_manual.name());
            dto.setFileUrl(pcOperatingManual);
            dtos.add(dto);
        }
        if (StringUtils.isNotBlank(phOperatingManual)) {
            SoftwareCopyRightFilesDto dto = new SoftwareCopyRightFilesDto();
            dto.setType(AiSoftWareCopyRightEnum.DOC_TYPE.ph_operating_manual.name());
            dto.setFileUrl(phOperatingManual);
            dtos.add(dto);
        }
        return dtos;
    }

}