<?php

namespace App\Models;

use App\Classes\General\Interfaces\Steppable;
use App\Classes\General\Interfaces\Transportable;
use App\Classes\General\Interfaces\Packable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class PackingList extends AbstractModel implements Transportable, Steppable, Packable
{
    use SoftDeletes;

    protected $table = 'packing_lists';

    protected $fillable = ['status'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
     */
    public function owner(): morphTo
    {
        return $this->morphTo();
    }

    public function containers(): BelongsToMany
    {
        return $this->BelongsToMany(Container::class, ContainerPackingList::class);
    }

    /**
     * @return MorphMany
     */
    public function steps(): morphMany
    {
        return $this->morphMany(Step::class, 'owner');
    }

    /**
     * @return HasMany
     */
    public function packages(): hasMany
    {
        return $this->hasMany(Package::class, 'packing_list_id');
    }

    /**
     * @return morphMany
     */
    public function transports(): morphMany
    {
        return $this->morphMany(Transport::class, 'owner');
    }

    /**
     * @return MorphMany
     */
    public function remarks(): morphMany
    {
        return $this->morphMany(Remark::class, 'owner');
    }

    /**
     * @return belongsToMany
     */
    public function packing_list_owner()
    {
        return $this->BelongsToMany(PackingList::class, 'packing_list_owner', 'owner_packing_list_id', 'packing_list_id');
    }

    /**
     * @return MorphMany
     */
    public function packingLists(): morphMany
    {
        return $this->morphMany(PackingList::class, 'owner');
    }
}
