package com.red.circle.other.app.inner.convertor.material.impl;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.inner.convertor.material.PropsResourcesInnerConvertor;
import com.red.circle.other.infra.database.rds.entity.props.PropsRedPacketSkin;
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO;
import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO;
import org.springframework.stereotype.Service;

import java.util.*;

@Service("propsResourcesInnerConvertorImplNew")
public class PropsResourcesInnerConvertorImpl implements PropsResourcesInnerConvertor {

    @Override
    public PropsResourcesDTO toPropsResourcesDTO(PropsSourceRecord propsSourceRecord) {
        if ( propsSourceRecord == null ) {
            return null;
        }

        PropsResourcesDTO propsResourcesDTO = new PropsResourcesDTO();

        propsResourcesDTO.setId( propsSourceRecord.getId() );
        propsResourcesDTO.setSysOrigin( propsSourceRecord.getSysOrigin() );
        propsResourcesDTO.setType( propsSourceRecord.getType() );
        propsResourcesDTO.setCode( propsSourceRecord.getCode() );
        propsResourcesDTO.setName( propsSourceRecord.getName() );
        propsResourcesDTO.setCover( propsSourceRecord.getCover() );
        propsResourcesDTO.setSourceUrl( propsSourceRecord.getSourceUrl() );
        propsResourcesDTO.setExpand( propsSourceRecord.getExpand() );
        propsResourcesDTO.setAmount( propsSourceRecord.getAmount() );
        propsResourcesDTO.setDel( propsSourceRecord.getDel() );
        propsResourcesDTO.setCreateTime( propsSourceRecord.getCreateTime() );
        propsResourcesDTO.setUpdateTime( propsSourceRecord.getUpdateTime() );
        propsResourcesDTO.setAdminFree( propsSourceRecord.getAdminFree() );

        return propsResourcesDTO;
    }

    @Override
    public Map<Long, PropsResourcesDTO> toMapPropsResourcesDTO(Map<Long, PropsSourceRecord> map) {
        if ( map == null ) {
            return null;
        }

        Map<Long, PropsResourcesDTO> map1 = new HashMap<Long, PropsResourcesDTO>( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) );

        for ( java.util.Map.Entry<Long, PropsSourceRecord> entry : map.entrySet() ) {
            Long key = entry.getKey();
            PropsResourcesDTO value = toPropsResourcesDTO( entry.getValue() );
            map1.put( key, value );
        }

        return map1;
    }

    @Override
    public List<PropsResourcesDTO> toListPropsResourcesDTO(List<PropsSourceRecord> propsResources) {
        if ( propsResources == null ) {
            return null;
        }

        List<PropsResourcesDTO> list = new ArrayList<PropsResourcesDTO>( propsResources.size() );
        for ( PropsSourceRecord propsSourceRecord : propsResources ) {
            list.add( toPropsResourcesDTO( propsSourceRecord ) );
        }

        return list;
    }

    @Override
    public PageResult<PropsResourcesDTO> toPagePropsResourcesDTO(PageResult<PropsSourceRecord> pageResult) {
        if ( pageResult == null ) {
            return null;
        }

        PageResult<PropsResourcesDTO> pageResult1 = new PageResult<PropsResourcesDTO>();

        pageResult1.setRecords( propsSourceRecordCollectionToPropsResourcesDTOCollection( pageResult.getRecords() ) );
        pageResult1.setTotal( pageResult.getTotal() );
        pageResult1.setSize( pageResult.getSize() );
        pageResult1.setCurrent( pageResult.getCurrent() );

        return pageResult1;
    }

    @Override
    public PropsSourceRecord toPropsSourceRecord(PropsResourcesDTO propsResourcesDTO) {
        if ( propsResourcesDTO == null ) {
            return null;
        }

        PropsSourceRecord propsSourceRecord = new PropsSourceRecord();

        propsSourceRecord.setCreateTime( propsResourcesDTO.getCreateTime() );
        propsSourceRecord.setUpdateTime( propsResourcesDTO.getUpdateTime() );
        propsSourceRecord.setId( propsResourcesDTO.getId() );
        propsSourceRecord.setSysOrigin( propsResourcesDTO.getSysOrigin() );
        propsSourceRecord.setType( propsResourcesDTO.getType() );
        propsSourceRecord.setCode( propsResourcesDTO.getCode() );
        propsSourceRecord.setName( propsResourcesDTO.getName() );
        propsSourceRecord.setCover( propsResourcesDTO.getCover() );
        propsSourceRecord.setSourceUrl( propsResourcesDTO.getSourceUrl() );
        propsSourceRecord.setExpand( propsResourcesDTO.getExpand() );
        propsSourceRecord.setAmount( propsResourcesDTO.getAmount() );
        propsSourceRecord.setDel( propsResourcesDTO.getDel() );
        propsSourceRecord.setAdminFree( propsResourcesDTO.getAdminFree() );
        return propsSourceRecord;
    }

    @Override
    public PropsRedPacketSkinDTO toPropsRedPacketSkinDTO(PropsRedPacketSkin skin) {
        if ( skin == null ) {
            return null;
        }

        PropsRedPacketSkinDTO propsRedPacketSkinDTO = new PropsRedPacketSkinDTO();

        propsRedPacketSkinDTO.setId( skin.getId() );
        propsRedPacketSkinDTO.setSysOrigin( skin.getSysOrigin() );
        propsRedPacketSkinDTO.setRoomSendCoverUrl( skin.getRoomSendCoverUrl() );
        propsRedPacketSkinDTO.setRoomOpenedUrl( skin.getRoomOpenedUrl() );
        propsRedPacketSkinDTO.setRoomNotOpenedUrl( skin.getRoomNotOpenedUrl() );
        propsRedPacketSkinDTO.setImSendCoverUrl( skin.getImSendCoverUrl() );
        propsRedPacketSkinDTO.setImOpenedUrl( skin.getImOpenedUrl() );
        propsRedPacketSkinDTO.setImNotOpenedUrl( skin.getImNotOpenedUrl() );
        propsRedPacketSkinDTO.setImOpenedUrlTwo( skin.getImOpenedUrlTwo() );
        return propsRedPacketSkinDTO;
    }

    protected Collection<PropsResourcesDTO> propsSourceRecordCollectionToPropsResourcesDTOCollection(Collection<PropsSourceRecord> collection) {
        if ( collection == null ) {
            return null;
        }

        Collection<PropsResourcesDTO> collection1 = new ArrayList<PropsResourcesDTO>( collection.size() );
        for ( PropsSourceRecord propsSourceRecord : collection ) {
            collection1.add( toPropsResourcesDTO( propsSourceRecord ) );
        }

        return collection1;
    }
}
