package com.alterdekim.game.service;

import com.alterdekim.flash.decompiler.mapper.OutputObjectCallback;
import com.alterdekim.game.controller.FileServerController;
import com.alterdekim.game.entity.MediaResourcePath;
import com.alterdekim.game.repository.MRTRepository;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@NoArgsConstructor
@Service
public class MRTService implements OutputObjectCallback {

    @Autowired
    private MRTRepository repository;

    @Override
    public void onOutputObjectReady(Object o) {
        var pathObj = (MediaResourcePath) o;
        pathObj.setVal(FileServerController.URL_PATH +"/"+pathObj.getVal());
        this.repository.save(pathObj);
    }

    public List<MediaResourcePath> getAll() {
        return this.repository.findAll();
    }

    public MediaResourcePath findById(Long id) {
        return this.repository.findById(id).get();
    }
}
