<?php

namespace App\Models\Crm;

use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Lead extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'channel_id', 'name', 'phone', 'wechat',
        'expected_date', 'source', 'status', 'owner_id',
        'remark', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'expected_date' => 'date',
            'status' => 'integer',
        ];
    }

    public function channel(): BelongsTo
    {
        return $this->belongsTo(Channel::class);
    }

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

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

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

    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }
}
