<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * Class PromotionUserProduct
 *
 * @property int $id
 * @property int $promotion_admin_id
 * @property int $promotion_user_id
 * @property int $promotion_admin_product_id
 * @property int $product_id
 * @property int|null $open_items
 * @property int|null $sell_items
 * @property float|null $used_budget_total
 * @property bool $active
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property Product $product
 * @property PromotionAdmin $promotion_admin
 * @property PromotionAdminProduct $promotion_admin_product
 * @property PromotionUser $promotion_user
 * @package App\Models
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct query()
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereOpenItems($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionAdminId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionAdminProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereSellItems($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereUsedBudgetTotal($value)
 * @mixin \Eloquent
 */
class PromotionUserProduct extends Model
{
	protected $table = 'promotion_user_products';

	protected $casts = [
		'promotion_admin_id' => 'int',
		'promotion_user_id' => 'int',
		'promotion_admin_product_id' => 'int',
		'product_id' => 'int',
		'open_items' => 'int',
		'sell_items' => 'int',
		'used_budget_total' => 'float',
		'active' => 'bool'
	];

	protected $fillable = [
		'promotion_admin_id',
		'promotion_user_id',
		'promotion_admin_product_id',
		'product_id',
		'open_items',
		'sell_items',
		'used_budget_total',
		'active'
	];

	public function product()
	{
		return $this->belongsTo(Product::class);
	}

	public function promotion_admin()
	{
		return $this->belongsTo(PromotionAdmin::class);
	}

	public function promotion_admin_product()
	{
		return $this->belongsTo(PromotionAdminProduct::class);
	}

	public function promotion_user()
	{
		return $this->belongsTo(PromotionUser::class);
	}

	public function isShow(){
		if($this->active && $this->product && $this->open_items > 0){
			return true;
		}
		return false;
	}
	
}
