<?php

namespace App\Models\Lookups;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class DamageReason extends Model
{
    use BelongsToTenant;

    public const TRANSIT = 'DMG_TRANSIT';

    public const WAREHOUSE = 'DMG_WAREHOUSE';

    public const CUSTOMER = 'DMG_CUSTOMER';

    public const EXPIRED = 'DMG_EXPIRED';

    public const ACCIDENT = 'DMG_ACCIDENT';

    public const OTHER = 'DMG_OTHER';

    protected $fillable = ['code', 'name', 'sort_order', 'is_active'];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    public static function findByCode(string $code): ?self
    {
        return static::query()->where('code', $code)->first();
    }
}
