package cn.reghao.oss.store.rpc;

import cn.reghao.oss.storeapi.dto.media.AudioInfo;
import cn.reghao.oss.storeapi.dto.media.ConvertedImageInfo;
import cn.reghao.oss.storeapi.dto.media.ImageInfo;
import cn.reghao.oss.storeapi.dto.media.VideoInfo;
import cn.reghao.oss.storeapi.iface.MediaService;
import cn.reghao.oss.store.task.MediaFileProcessor;
import cn.reghao.oss.store.util.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author reghao
 * @date 2024-03-07 09:52:59
 */
@Slf4j
@DubboService
@Service
public class MediaServiceImpl implements MediaService {
    private final LocalDateTime epoch = LocalDateTime.parse("1970-01-01T08:00");
    private final MediaFileProcessor mediaFileProcessor;

    public MediaServiceImpl(MediaFileProcessor mediaFileProcessor) {
        this.mediaFileProcessor = mediaFileProcessor;
    }

    public VideoInfo getVideoInfo(String videoFileId) {
        try {
            VideoInfo videoInfo = mediaFileProcessor.getVideoInfo(videoFileId);
            return videoInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public ImageInfo getImageInfo(String imageFileId) {
        try {
            ImageInfo imageInfo = mediaFileProcessor.getImageInfo(imageFileId);
            return imageInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }


        return null;
    }

    public List<ImageInfo> getImagesInfo(List<String> imageFileIds) {
        return mediaFileProcessor.getImagesInfo(imageFileIds);
    }

    public List<ConvertedImageInfo> getWebpInfo(int loginUser, List<String> imageFileIds) {
        UserContext userContext = new UserContext(loginUser);
        return mediaFileProcessor.getWebpInfos(imageFileIds);
    }

    @Override
    public AudioInfo getAudioInfo(String audioFileId) {
        try {
            AudioInfo audioInfo = mediaFileProcessor.getAudioInfo(audioFileId);
            return audioInfo;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
