<?php

namespace App\Models;

use App\Traits\Multitenantable;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class OutletInventory extends Model
{
    use SoftDeletes, Multitenantable;

    public $primaryKey = 'uuid';

    public $incrementing = false;

    public $keyType = 'string';
    protected $fillable = [
        'uuid',
        'tenant_id',
        'outlet_id',
        'item_type',
        'item_id',
        'stock_type',
        'stock',
        'selling_price',
        'cost_price',
        'purchase_price',
        'is_delete_by_owner'
    ];

    protected $casts = [
        'is_delete_by_owner' => 'boolean',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    protected $dates = ['deleted_at'];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function item()
    {
        return $this->morphTo('item', 'item_type', 'item_id');
    }

    public function stockCards()
    { 
        return $this->hasMany(StockCard::class, 'outlet_inventory_id');
    }
}
