<?php

namespace App\Modules\CRM\Models;

use App\Modules\Invoice\Models\Customer;
use App\Modules\Tenant\Models\Company;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Lead extends Model
{
    use HasFactory;

    protected $table = 'crm_leads';

    protected $fillable = [
        'company_id',
        'customer_id',
        'name',
        'company_name',
        'email',
        'phone',
        'source',
        'stage',
        'deal_value',
        'next_follow_up_at',
        'notes',
        'status',
    ];

    protected $casts = [
        'deal_value' => 'decimal:2',
        'next_follow_up_at' => 'date:Y-m-d',
    ];

    /**
     * @return BelongsTo<Company, Lead>
     */
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    /**
     * @return BelongsTo<Customer, Lead>
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return HasMany<Activity>
     */
    public function activities(): HasMany
    {
        return $this->hasMany(Activity::class);
    }
}
