<?php

namespace App\Models;

use App\Services\Repositories\GroupRepository;
use App\Services\Repositories\ProductRepository;
use Illuminate\Database\Eloquent\Model;

class OrderProduct extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'count',
        'product_cost',
        'total',
        'order_id',
        'product_id',
    ];

    public function getProductAttribute()
    {
        $productRepository = app(ProductRepository::class);
        $product = $productRepository->checkItem($this->product_id);
        return $product;
    }

    public function getProductGroupAttribute()
    {
        $group= $this->product->group;
        $groupId= $group->group_id ?? null;
        $group = (new GroupRepository())->getItem($groupId);
        return $group;
    }

}
