<?php

namespace App\Models\Tenant;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Client extends Model
{
    use BelongsToTenant, SoftDeletes;

    protected $fillable = [
        'company_id', 'type', 'name', 'company_name',
        'phone', 'phone_alt', 'email',
        'telegram', 'whatsapp', 'viber',
        'source', 'marketing_channel', 'status',
        'balance', 'discount_pct', 'notes',
        'assigned_to', 'last_contact_at',
    ];

    protected $casts = [
        'balance' => 'decimal:2',
        'discount_pct' => 'decimal:2',
        'last_contact_at' => 'datetime',
    ];

    public function vehicles(): HasMany
    {
        return $this->hasMany(Vehicle::class);
    }

    public function workOrders(): HasMany
    {
        return $this->hasMany(WorkOrder::class);
    }

    public function payments(): HasMany
    {
        return $this->hasMany(Payment::class);
    }

    public function assignedTo(): BelongsTo
    {
        return $this->belongsTo(User::class, 'assigned_to');
    }
}
