<?php

namespace App\Models\Lookups;

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

class ReturnReason extends Model
{
    use BelongsToTenant;

    public const WRONG_ITEM = 'WRONG_ITEM';

    public const OVERSTOCK = 'OVERSTOCK';

    public const QUALITY = 'QUALITY';

    public const EXPIRED = 'EXPIRED';

    public const DAMAGE_TRANSIT = 'DAMAGE_TRANSIT';

    public const DAMAGE_WAREHOUSE = 'DAMAGE_WAREHOUSE';

    public const DAMAGE_CUSTOMER = 'DAMAGE_CUSTOMER';

    public const MISTAKENLY_ORDERED = 'MISTAKENLY_ORDERED';

    public const OTHER = 'OTHER';

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

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

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