<?php
// Copyright (c) Pickware GmbH. All rights reserved.
// This file is part of software that is released under a proprietary license.
// You must not copy, modify, distribute, make publicly available, or execute
// its contents or parts thereof without express permission by the copyright
// holder, unless otherwise permitted by law.

namespace Shopware\CustomModels\ViisonPickwareMobile\PickProfile;

use Doctrine\ORM\Mapping as ORM;
use Shopware\Components\Model\ModelEntity;
use Shopware\Models\Payment\Payment;

/**
 * @ORM\Entity()
 * @ORM\Table(name="pickware_wms_pick_profile_prioritized_payment_methods", uniqueConstraints={
 *      @ORM\UniqueConstraint(name="pickProfileId_paymentMethodId", columns={
 *          "pickProfileId",
 *          "paymentMethodId"
 *      })
 * })
 */
class PickProfilePrioritizedPaymentMethod extends ModelEntity
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Id
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\Column(name="pickProfileId", type="integer", nullable=false)
     */
    private $pickProfileId;

    /**
     * @var int
     *
     * @ORM\Column(name="paymentMethodId", type="integer", nullable=false)
     */
    private $paymentMethodId;

    /**
     * OWNING SIDE
     *
     * @var PickProfile
     *
     * @ORM\ManyToOne(targetEntity="Shopware\CustomModels\ViisonPickwareMobile\PickProfile\PickProfile", inversedBy="prioritizedPaymentMethods")
     * @ORM\JoinColumn(name="pickProfileId", referencedColumnName="id", onDelete="CASCADE")
     */
    private $pickProfile;

    /**
     * OWNING SIDE
     *
     * @var Payment
     *
     * @ORM\ManyToOne(targetEntity="Shopware\Models\Payment\Payment")
     * @ORM\JoinColumn(name="paymentMethodId", referencedColumnName="id", onDelete="CASCADE")
     */
    private $paymentMethod;

    /**
     * @param PickProfile $pickProfile
     * @param Payment $paymentMethod
     */
    public function __construct(PickProfile $pickProfile, Payment $paymentMethod)
    {
        $this->pickProfile = $pickProfile;
        $this->paymentMethod = $paymentMethod;
        if (!$this->pickProfile->getPrioritizedPaymentMethods()->contains($this)) {
            $this->pickProfile->getPrioritizedPaymentMethods()->add($this);
        }

        // Explicitly set the both IDs which form the unique identifier of this entity, because Doctrine won't do it,
        // even though we have already set the associated entities
        $this->pickProfileId = $pickProfile->getId();
        $this->paymentMethodId = $paymentMethod->getId();
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return PickProfile
     */
    public function getPickProfile()
    {
        return $this->pickProfile;
    }

    /**
     * @return Payment
     */
    public function getPaymentMethod()
    {
        return $this->paymentMethod;
    }
}
