<?php

namespace App\Models\LeadSource;

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 = [
        'lead_source_id',
        'slug',
        'status',
        'display_name',
        'url',
        'key'
    ];

    use 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);
    }
}
