<?php

declare(strict_types=1);

namespace App\Models;

use App\Models\Concerns\GeneratesDberpCode;
use App\Models\Concerns\HasDberpAuditTrail;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class DberpPurchaseInquiry extends Model
{
    use GeneratesDberpCode;
    use HasDberpAuditTrail;

    protected $table = 'dberp_purchase_inquiries';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'code',
        'purchase_request_id',
        'purchase_request_code',
        'inquiry_date',
        'handler_employee_id',
        'status',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'purchase_request_id' => 'integer',
            'inquiry_date' => 'date',
            'handler_employee_id' => 'integer',
        ];
    }

    public function getDberpNumberScope(): string
    {
        return 'purchase_inquiry';
    }

    public function getDberpAuditActionPrefix(): string
    {
        return 'dberp.purchase_inquiry';
    }

    /**
     * @return list<string>
     */
    public function getDberpAuditFields(): array
    {
        return $this->getFillable();
    }

    public function purchaseRequest(): BelongsTo
    {
        return $this->belongsTo(DberpPurchaseRequest::class, 'purchase_request_id');
    }

    public function handlerEmployee(): BelongsTo
    {
        return $this->belongsTo(DberpEmployee::class, 'handler_employee_id');
    }

    public function items(): HasMany
    {
        return $this->hasMany(DberpPurchaseInquiryItem::class, 'inquiry_id');
    }

    public function quotes(): HasMany
    {
        return $this->hasMany(DberpPurchaseInquiryQuote::class, 'purchase_inquiry_id');
    }
}
