package com.samsung.embo.formula.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.samsung.common.IdGenService;
import com.samsung.embo.formula.FormulaService;
import com.samsung.embo.formula.dao.FormulaDao;
import com.samsung.embo.formula.entity.Formula;
import com.samsung.resource.FileManagerService;

@Service
public class FormulaServiceImpl implements FormulaService {

	private static final String DOWNLOAD_TYPE = "FORMULA";
	private final IdGenService idGenService;
	private final FileManagerService fileManagerService;
	private final FormulaDao formulaDao;

	public FormulaServiceImpl(IdGenService idGenService, FileManagerService fileManagerService, FormulaDao formulaDao) {

		this.idGenService = idGenService;
		this.fileManagerService = fileManagerService;
		this.formulaDao = formulaDao;
	}

	@Override
	public String insertFormula(Formula formula) {
		formula.setFmId(idGenService.getNextStringId());
		formulaDao.insertFormula(formula);
		fileManagerService.updateFileRefId(formula.getFmId(), formula.getAttachments(), DOWNLOAD_TYPE);
		return formula.getFmId();
	}
	
	@Override
	public String updateFormula(Formula formula) {
		formulaDao.updateFormula(formula);
		fileManagerService.updateFileRefId(formula.getFmId(), formula.getAttachments(), DOWNLOAD_TYPE);
		return formula.getFmId();
	}

	@Override
	public List<Map<String, Object>> selectFormula(Map<String, Object> params) {

		
		return formulaDao.selectFormula(params);
	}

	@Override
	public int deleteFormula(Map<String, Object> params) {
		
		return formulaDao.deleteFormula(params);
	}

	@Override
	public Map<String, Object> getFormula(Map<String, Object> params) {
		
		return formulaDao.getFormula(params);
	}

	

}
