package com.starry.admin.modules.weichat.assembler;

import com.starry.admin.modules.media.entity.PlayMediaEntity;
import com.starry.admin.modules.weichat.entity.clerk.MediaVo;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public final class MediaAssembler {

    private MediaAssembler() {
    }

    public static MediaVo toVo(PlayMediaEntity entity) {
        if (entity == null) {
            return null;
        }
        MediaVo vo = new MediaVo();
        vo.setId(entity.getId());
        vo.setMediaId(entity.getId());
        vo.setKind(entity.getKind());
        vo.setStatus(entity.getStatus());
        vo.setUrl(entity.getUrl());
        vo.setCoverUrl(entity.getCoverUrl());
        vo.setDurationMs(entity.getDurationMs());
        vo.setWidth(entity.getWidth());
        vo.setHeight(entity.getHeight());
        vo.setSizeBytes(entity.getSizeBytes());
        vo.setOrderIndex(entity.getOrderIndex());
        vo.setMetadata(entity.getMetadata());
        return vo;
    }

    public static List<MediaVo> toVoList(List<PlayMediaEntity> entities) {
        if (entities == null) {
            return Collections.emptyList();
        }
        return entities.stream()
                .filter(Objects::nonNull)
                .map(MediaAssembler::toVo)
                .collect(Collectors.toList());
    }
}
