'use strict';

const defaultInventarioService = require('../../services/inventarioService');
const { validateRecipeUpdate } = require('./schemas');

function service(deps = {}) {
  return deps.inventarioService || defaultInventarioService;
}

async function updateRecipe(command, _config = {}, deps = {}) {
  const payload = validateRecipeUpdate(command.payload || {});
  const result = await service(deps).guardarReceta(payload.idproducto, payload.lines);
  return {
    ok: true,
    entity_type: 'recipe',
    entity_id: payload.idproducto,
    lines: payload.lines.length,
    result,
  };
}

module.exports = { updateRecipe };
