<?php

namespace App\Models\Orders;

use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ClientGroup extends Model
{
    use Auditable, BelongsToTenant, ModelTrait, SoftDeletes;

    protected $fillable = [
        'tenant_id',
        'group_code',
        'group_name',
        'price_rate',
        'is_active',
        'created_by',
        'updated_by',
        'deleted_by',
    ];

    protected $casts = [
        'price_rate' => 'decimal:4',
        'is_active' => 'boolean',
    ];

    // Clients 관계
    public function clients()
    {
        return $this->hasMany(Client::class, 'client_group_id');
    }

    // 스코프
    public function scopeActive($query)
    {
        return $query->where('is_active', 1);
    }

    public function scopeCode($query, string $code)
    {
        return $query->where('group_code', $code);
    }
}
