package com.utopiaindustries.service;

import com.utopiaindustries.dao.ctp.BundleDAO;
import com.utopiaindustries.dao.ctp.FinishedItemDAO;
import com.utopiaindustries.dao.ctp.JobCardDAO;
import com.utopiaindustries.dao.ctp.MasterBundleDAO;
import com.utopiaindustries.model.ctp.Bundle;
import com.utopiaindustries.model.ctp.FinishedItem;
import com.utopiaindustries.model.ctp.MasterBundle;
import org.springframework.stereotype.Service;

@Service
public class InventoryArtifactService {

    private final BundleDAO bundleDAO;
    private final MasterBundleDAO masterBundleDAO;
    private final FinishedItemDAO finishedItemDAO;
    private final JobCardDAO jobCardDAO;

    public InventoryArtifactService(BundleDAO bundleDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, JobCardDAO jobCardDAO) {
        this.bundleDAO = bundleDAO;
        this.masterBundleDAO = masterBundleDAO;
        this.finishedItemDAO = finishedItemDAO;
        this.jobCardDAO = jobCardDAO;
    }

    /*
    *  get bundle
    * */
    public Bundle findBundleById( long id ) {
        Bundle bundle = bundleDAO.find( id );
        bundle.setMasterBundle( masterBundleDAO.find( bundle.getMasterBundleId() ) );
        return bundle;
    }

    /*
    *  get master bundle
    * */
//    public MasterBundle findMasterBundleById( long id ){
//        MasterBundle masterBundle = masterBundleDAO.find( id );
//        masterBundle.setBundles( bundleDAO.findByMasterId( id ) );
//        masterBundle.setItems( finishedItemDAO.findByMasterId( id ) );
//        return masterBundle;
//    }

    /*
    *  get finished Item
    * */
    public FinishedItem findFinishedItemById( long id ){
        FinishedItem finishedItem = finishedItemDAO.find( id );
        finishedItem.setJobCard( jobCardDAO.find( finishedItem.getJobCardId() ) );
        return finishedItem;
    }

    /*
     *  get finished Items By Job Card ID
     * */
    public FinishedItem findByJobCardId( long id ){
        FinishedItem finishedItem = finishedItemDAO.find( id );
        finishedItem.setJobCard( jobCardDAO.find( finishedItem.getJobCardId() ) );
        return finishedItem;
    }
}
