<?php

namespace App\Models\LeadSource;

use App\Trait\BelongsToSolicitor;
use App\Trait\HasSlug;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;

class LeadSourceEndpoint extends Model {
    protected $table = 'lead_source_endpoints';
    protected $fillable = [
        'solicitor_id',
        'lead_source_id',
        'slug',
        'status',
        'display_name',
        'url',
        'key'
    ];

    use BelongsToSolicitor, HasSlug, SoftDeletes, HasFactory;

    protected static function booted() {
        parent::booted();
        static::creating(function ($model) {
            $model->key = Str::random(40);
        });
    }

    public function leadSource() {
        return $this->belongsTo(LeadSource::class);
    }
}
