package com.alterdekim.game.service;

import com.alterdekim.flash.decompiler.mapper.OutputObjectCallback;
import com.alterdekim.game.entity.PhoneIcon;
import com.alterdekim.game.entity.PhoneSkin;
import com.alterdekim.game.repository.PhoneIconRepository;
import com.alterdekim.game.repository.PhoneSkinRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class PhoneIconService implements OutputObjectCallback {
    @Autowired
    private PhoneIconRepository repository;

    @Autowired
    private PhoneSkinRepository skinRepository;

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

    public void save(PhoneSkin skin) {
        this.skinRepository.save(skin);
    }

    public List<PhoneIcon> findAll() {
        return repository.findAll();
    }

    public Optional<PhoneSkin> findSkinById(Long phoneId) {
        return this.skinRepository.findById(phoneId);
    }

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