<?php

namespace App\Models;

use Carbon\Traits\Timestamp;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;

use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class Document
 * @package App\Models
 *
 * @property int $owner_id
 * @property int $owner_type
 * @property int $document_type
 * @property string $reference
 * @property int $status
 * @property int $approver
 * @property string $issued_date
 * @property string $expired_date
 * @property string $approved_date
 */
class Document extends AbstractModel
{
    use SoftDeletes;

    protected $table = 'documents';

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'deleted_at' => 'datetime',
        ];
    }

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

    /**
     * @return HasMany
     */
    public function files(): HasMany
    {
        return $this->hasMany(File::class, 'document_id');
    }

    /**
     * @return HasOne
     */
    public function approver(): HasOne
    {
        return $this->hasOne(User::class, 'id', 'approver');
    }

}
