package com.alterdekim.game.service;

import com.alterdekim.flash.decompiler.mapper.OutputObjectCallback;
import com.alterdekim.game.entity.MediaResource;
import com.alterdekim.game.repository.MediaResourceRepository;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@NoArgsConstructor
public class MRService implements OutputObjectCallback {

    @Autowired
    private MediaResourceRepository repository;

    @Override
    public void onOutputObjectReady(Object o) {
        this.repository.save((MediaResource) o);
    }

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

    public Optional<MediaResource> findById(Long id) {
        return this.repository.findById(id);
    }

    public Optional<MediaResource> findByUrl(String url, Integer tid) {
        return this.repository.findByUrl(url, tid);
    }
}
