<?php

/* * ********************************************************************************** */
/*      This file is part of the Thelia package.                                     */
/*                                                                                   */
/*      Copyright (c) OpenStudio                                                     */
/*      email : dev@thelia.net                                                       */
/*      web : http://www.thelia.net                                                  */
/*                                                                                   */
/*      For the full copyright and license information, please view the LICENSE.txt  */
/*      file that was distributed with this source code.                             */
/* * ********************************************************************************** */
/* * ********************************************************************************** */

namespace ArtabanMarketplace\Controller;

use ArtabanMarketplace\Controller\Base\BaseController;
use ArtabanMarketplace\ArtabanMarketplace as ArtabanMarketplaceModule;
use ArtabanMarketplace\Model\AmpSeller;
use ArtabanMarketplace\Model\AmpSellerQuery;
use ArtabanMarketplace\Model\AmpSellerAdminQuery;
use ArtabanMarketplace\Model\AmpSellerAdmin;
use Propel\Runtime\Propel;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Thelia\Core\HttpFoundation\JsonResponse;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Tools\URL;

/**
 * Class SellerProfilController
 * @package ArtabanMarketplace\Controller
 */
class SellerProfilController extends BaseController {

    /**
     * Load an existing object from the database
     */
    protected function getExistingObject() {
        return AmpSellerQuery::create()->findPk($this->getObjectIdFromSession());
    }

    /**
     * Hydrate the update form for this object, before passing it to the update template
     *
     * @param mixed $object
     */
    protected function hydrateObjectForm($object) {
        $data = array(
            "id" => $object->getId(),
            "title" => $object->getTitle(),
            "address1" => $object->getAddress1(),
            "address2" => $object->getAddress2(),
            "address3" => $object->getAddress3(),
            "zipcode" => $object->getZipcode(),
            "city" => $object->getCity(),
            "country_id" => $object->getCountryId(),
            "description" => $object->getDescription(),
            "latitude" => $object->getLatitude(),
            "longitude" => $object->getLongitude(),
            "email" => $object->getEmail(),
            "phone" => $object->getPhone(),
            "fax" => $object->getFax(),
            "url" => $object->getUrl(),
            "facebook" => $object->getFacebook(),
            "twitter" => $object->getTwitter(),
            "pinterest" => $object->getPinterest(),
            "google" => $object->getGoogle(),
            "youtube" => $object->getYoutube(),
            "instagram" => $object->getInstagram(),
        );

        return $this->getUpdateForm($data);
    }

    const CONTROLLER_ENTITY_NAME = "seller";

    /**
     * Use to get render of list
     * @return mixed
     */
    protected function getListRenderTemplate() {
        return $this->render("sellers");
    }

    /**
     * Use to get Edit render
     * @return mixed
     */
    protected function getEditRenderTemplate() {
        return $this->render("seller-profil");
    }

    /**
     * Use to get Create render
     * @return mixed
     */
    protected function getCreateRenderTemplate() {
        // TODO: Implement getCreateRenderTemplate() method.
    }

    /**
     * @return mixed
     */
    protected function getObjectId($object) {
        /** @var Seller $object */
        return $object->getId();
    }
    
    /**
     * @return mixed
     */
    protected function getObjectIdFromSession() {
        $admin_id = $this->getSession()->getAdminUser()->getId();
        $seller_link_admin_object = AmpSellerAdminQuery::create()->findOneByAdminId($admin_id);
        $object= AmpSellerQuery::create()->findOneById($seller_link_admin_object->getAmpSellerID());
        /** @var Seller id */
        return $object->getId();
    }

    protected function redirectToListTemplate() {
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/artabanmarketplace/seller/profil"));
    }

    protected function redirectToEditionTemplate() {
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/artabanmarketplace/seller/profil"));
    }

}
