<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    const PRODUCT_RELATION_STATUS_TO_ADD = 'to_add';
    const PRODUCT_RELATION_STATUS_TO_REMOVE = 'to_remove';
    const PRODUCT_RELATION_STATUS_SYNCED = 'synced';

    const ITEM_TYPE_ITEM = 'item';
    const ITEM_TYPE_RESOURCE = 'resource';

    const SHOPIFY_STATUS_ACTIVE = 'ACTIVE';
    const SHOPIFY_STATUS_ARCHIVED = 'ARCHIVED';
    const NAV_ACTIVE_STATUS = 'Standard';


    public function variants()
    {
        return $this->hasMany(Variant::class);
    }

    public function meta()
    {
        return $this->hasMany(ProductMeta::class);
    }

    public function collections()
    {
        return $this->belongsToMany(ProductCollection::class, 'product_collections', 'product_id', 'collection_id')->withPivot('status');
    }

    public function catalogs()
    {
        return $this->belongsToMany(Catalog::class, 'product_catalogs', 'product_id', 'catalog_id')->withPivot('status');
    }

    public function getShopifyStatusAttribute()
    {
        return !$this->disabled ? self::SHOPIFY_STATUS_ACTIVE : self::SHOPIFY_STATUS_ARCHIVED;
    }
}
