<?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 DberpCustomerPriceRule extends Model
{
    use HasDberpAuditTrail;

    protected $table = 'dberp_customer_price_rules';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'rule_name',
        'rule_type',
        'customer_id',
        'price_level_code',
        'product_id',
        'external_product_id',
        'external_sku',
        'product_spec_snapshot',
        'unit_price',
        'sort_order',
        'valid_from',
        'valid_until',
        'status',
        'source_system',
        'channel_code',
        'external_reference_id',
        'remark',
    ];

    protected function casts(): array
    {
        return [
            'customer_id' => 'integer',
            'product_id' => 'integer',
            'unit_price' => 'decimal:4',
            'sort_order' => 'integer',
            'valid_from' => 'date',
            'valid_until' => 'date',
        ];
    }

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

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

    public function customer(): BelongsTo
    {
        return $this->belongsTo(DberpCustomer::class, 'customer_id');
    }

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