<?php

namespace Modules\Inventory\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Core\Traits\HasStatus;
use Modules\Inventory\Models\Traits\HasInventoryDepartment;
use Modules\Inventory\Models\Traits\HasProduct;
use Modules\Inventory\Models\Traits\HasStock;
use Modules\Inventory\Models\Traits\HasStockBatch;

class StockMovement extends Model
{
    use HasStatus,
        HasStock,
        HasStockBatch,
        HasProduct,
        HasInventoryDepartment,
        SoftDeletes;

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
        'fiscal_year_id',
        'accounting_period_id',
        'stock_id',
        'stock_batch_id',
        'product_id',
        'inventory_department_id',
        'type',
        'direction',
        'qty',
        'unit_cost',
        'total_cost',
        'referenceable_type',
        'referenceable_id',
        'performed_at',
        'note',
    ];

    protected $casts = [
        'performed_at' => 'datetime',
    ];

    public function referenceable()
    {
        return $this->morphTo();
    }

    // Use this when attaching fiscal context.
    /* $data = $this->fiscalPeriodService->attach(
        $data,
        'performed_at'
    ); */
}
