<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

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

/**
 * Class UserWhitelabelProduct
 *
 * @property int $id
 * @property int $user_id
 * @property int $product_id
 * @property string|null $info
 * @property string|null $attributes
 * @property string|null $options
 * @property bool $active
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property Product $product
 * @property User $user
 * @package App\Models
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ProductImage> $whitelabel_images
 * @property-read int|null $whitelabel_images_count
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereAttributes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereInfo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereOptions($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWhitelabelProduct whereUserId($value)
 * @mixin \Eloquent
 */
class UserWhitelabelProduct extends Model
{
	protected $table = 'user_whitelabel_products';

	protected $casts = [
		'user_id' => 'int',
		'product_id' => 'int',
		'active' => 'bool',
		'attributes' => 'object',
		'options' => 'object'

	];

	protected $fillable = [
		'user_id',
		'product_id',
		'info',
		'attributes',
		'options',
		'active'
	];

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

	public function user()
	{
		return $this->belongsTo(User::class);
	}

	public function whitelabel_images(){
        return $this->hasMany(ProductImage::class, 'user_wl_product_id', 'id')->where('type','=', 'uwllogo')->orderBy('pos');
    }
}
