<?php

namespace App\Models;

use App\Models\Concerns\BelongsToBusiness;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class TradeDocument extends Model
{
    use BelongsToBusiness, SoftDeletes;
    protected $guarded = ['id'];
    protected $casts = ['issue_date' => 'date', 'due_date' => 'date', 'approved_at' => 'datetime', 'paid_at' => 'datetime',
        'requested_at'=>'datetime','customer_decided_at'=>'datetime','sent_at'=>'datetime'];
    public function lines() { return $this->hasMany(TradeDocumentLine::class); }
    public function deal() { return $this->belongsTo(Deal::class); }
    public function parent() { return $this->belongsTo(self::class, 'parent_document_id'); }
    public function template() { return $this->belongsTo(DocumentTemplate::class); }
    public function requester() { return $this->belongsTo(User::class, 'requested_by'); }
    public function approver() { return $this->belongsTo(User::class, 'approved_by'); }
    public function approvalHistories() { return $this->hasMany(TradeDocumentApprovalHistory::class); }
    public function payments() { return $this->hasMany(TradeDocumentPayment::class); }
    public function deliveries() { return $this->hasMany(TradeDocumentDelivery::class); }
    public function transaction() { return $this->belongsTo(Transaction::class); }
}
