package com.alterdekim.game.service;

import com.alterdekim.flash.decompiler.mapper.OutputObjectCallback;
import com.alterdekim.game.entity.Catalog;
import com.alterdekim.game.entity.CatalogObject;
import com.alterdekim.game.repository.CatalogObjectRepository;
import com.alterdekim.game.repository.CatalogRepository;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@NoArgsConstructor
@Service
public class CatalogService implements OutputObjectCallback {

    @Autowired
    private CatalogRepository repository;

    @Autowired
    private CatalogObjectRepository objectRepository;

    @Override
    public void onOutputObjectReady(Object o) {
        if( o.getClass().equals(Catalog.class) ) {
            this.repository.save((Catalog) o);
            return;
        }
        this.objectRepository.save((CatalogObject) o);
    }
}
