<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * @property int $id
 * @property string $name
 * @property string $code
 * @property string|null $description
 * @property bool $is_positive
 * @property bool $is_active
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $badge_class
 * @property-read mixed $icon
 *
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType active()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType negative()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType positive()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereIsActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereIsPositive($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientBalanceType whereUpdatedAt($value)
 *
 * @mixin \Eloquent
 */
class ClientBalanceType extends Model
{
    use HasFactory;

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

    protected $casts = [
        'is_positive' => 'boolean',
        'is_active' => 'boolean',
    ];

    /**
     * Aktif işlem tiplerini getir
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Pozitif işlem tiplerini getir (bakiye artırır)
     */
    public function scopePositive($query)
    {
        return $query->where('is_positive', true);
    }

    /**
     * Negatif işlem tiplerini getir (bakiye azaltır)
     */
    public function scopeNegative($query)
    {
        return $query->where('is_positive', false);
    }

    /**
     * İşlem tipi rengi (badge için)
     */
    public function getBadgeClassAttribute()
    {
        return $this->is_positive ? 'bg-success' : 'bg-danger';
    }

    /**
     * İşlem tipi ikonu
     */
    public function getIconAttribute()
    {
        return $this->is_positive ? 'fa-plus' : 'fa-minus';
    }
}
