<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AllocationRule extends Model
{
    public const TYPE_STORE_PREFERENCE = 'store_preference';
    public const TYPE_NEAREST_STORE = 'nearest_store';
    public const TYPE_HIGHEST_STOCK = 'highest_stock';
    public const TYPE_PRIORITY_STORE = 'priority_store';
    public const TYPE_WAREHOUSE_FALLBACK = 'warehouse_fallback';
    public const TYPE_SPLIT_ORDERS = 'split_orders';
    public const TYPE_BACKORDERS = 'backorders';

    protected $fillable = [
        'company_id',
        'name',
        'rule_type',
        'priority',
        'is_active',
        'config',
    ];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'priority' => 'integer',
            'config' => 'array',
        ];
    }

    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }
}
