<?php

namespace ArtabanMarketplace\Model;

use ArtabanMarketplace\ArtabanMarketplace;
use ArtabanMarketplace\Model\Base\AmpSellerImage as BaseAmpSellerImage;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Router;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Translation\Translator;
use Thelia\Files\FileModelInterface;
use Thelia\Files\FileModelParentInterface;
use Thelia\Form\BaseForm;
use Thelia\Model\Breadcrumb\BreadcrumbInterface;
use Thelia\Model\Tools\ModelEventDispatcherTrait;
use Thelia\Model\Tools\PositionManagementTrait;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Tools\URL;

class AmpSellerImage extends BaseAmpSellerImage implements FileModelInterface
{
    use ModelEventDispatcherTrait;
    use PositionManagementTrait;

    public function preInsert(ConnectionInterface $con = null)
    {
        $this->setPosition($this->getNextPosition());

        return true;
    }

    /**
     * Set file parent id
     *
     * @param int $parentId parent id
     *
     * @return $this
     */
    public function setParentId($parentId)
    {
        return $this->setAmpSellerId($parentId);
    }

    /**
     * Get file parent id
     *
     * @return int parent id
     */
    public function getParentId()
    {
        return $this->getAmpSellerId();
    }

    /**
     * @return FileModelParentInterface the parent file model
     */
    public function getParentFileModel()
    {
        return new AmpSeller();
    }

    /**
     * Get the ID of the form used to change this object information
     *
     * @return BaseForm the form
     */
    public function getUpdateFormId()
    {
        return 'seller_image.update';
    }

    /**
     * Get the form instance used to change this object information
     *
     * @param Request $request the current request
     *
     * @return BaseForm the form
     */
    public function getUpdateFormInstance(Request $request)
    {
        return new SellerImageUpdateForm($request);
    }

    /**
     * @return string the path to the upload directory where files are stored, without final slash
     */
    public function getUploadDir()
    {
        return ArtabanMarketplace::getAmpSellerImagesFolder();
    }

    /**
     * @param int $objectId the object ID
     *
     * @return string the URL to redirect to after update from the back-office
     */
    public function getRedirectionUrl()
    {
        return "/admin/module/artabanmarketplace/seller/edit?seller_id={$this->getAmpSellerId()}";
    }

    /**
     * Get the Query instance for this object
     *
     * @return ModelCriteria
     */
    public function getQueryInstance()
    {
        return AmpSellerImageQuery::create();
    }

    public function createQuery()
    {
        $query = AmpSellerImageQuery::create();
        !is_null($this->amp_seller_id) and $query->filterByAmpSellerId($this->amp_seller_id);
        return $query;
    }
}
