<?php

declare(strict_types=1);

namespace App\Models;

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

class DberpInventoryRule extends Model
{
    use HasDberpAuditTrail;

    protected $table = 'dberp_inventory_rules';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'product_id',
        'warehouse_id',
        'manages_batch',
        'manages_serial_number',
        'manages_expiry',
        'safety_stock',
        'reorder_point',
        'replenish_target_quantity',
        'expiry_warning_days',
        'inventory_issue_policy',
        'warning_enabled',
        'replenishment_enabled',
        'is_enabled',
        'sort_order',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'product_id' => 'integer',
            'warehouse_id' => 'integer',
            'manages_batch' => 'boolean',
            'manages_serial_number' => 'boolean',
            'manages_expiry' => 'boolean',
            'safety_stock' => 'decimal:4',
            'reorder_point' => 'decimal:4',
            'replenish_target_quantity' => 'decimal:4',
            'expiry_warning_days' => 'integer',
            'warning_enabled' => 'boolean',
            'replenishment_enabled' => 'boolean',
            'is_enabled' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

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

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

    public function product(): BelongsTo
    {
        return $this->belongsTo(DberpProduct::class, 'product_id');
    }

    public function warehouse(): BelongsTo
    {
        return $this->belongsTo(DberpWarehouse::class, 'warehouse_id');
    }
}