<?php

namespace Webkul\DamBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use Webkul\DamBundle\Entity\AssetCategory;

class AddCategoryCommand extends ContainerAwareCommand
{
    /** @var EntityManager */
    protected $em;

    public function __construct(
        $em
    ) {
        $this->em = $em;
        parent::__construct();
    }

    protected function configure()
    {
        parent::configure();

        $this->setName('dam:asset:category')
            ->setDescription('add Master Category');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        //remove from routing.yml
            $em = $this->em;
            $repo = $em->getRepository('WebkulDamBundle:AssetCategory');
            $field = $repo->findOneBy([
                        'code' => 'master_asset'
                    ]);
            if(!$field) {
                $field = new AssetCategory();
                $field->setCode('master_asset');
                $field->setLevel('0');
                $field->setRight('2');
                $field->setLeft('1');
                
                $em->persist($field);
                $em->flush();
            }      
        

        $output->writeln("Dam module has been successfully Installed.");
    }

   
}