<?php

namespace App\Models;

use App\Models\Concerns\BelongsToBusiness;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Survey extends Model
{
    use BelongsToBusiness, SoftDeletes;
    protected $guarded = ['id'];
    protected $casts = ['questions' => 'array', 'start_date' => 'date', 'end_date' => 'date', 'allow_anonymous' => 'boolean'];
    public function owner(){return $this->belongsTo(User::class,'owner_id');}
    public function questionRecords(){return $this->hasMany(SurveyQuestion::class)->orderBy('position');}
    public function responses(){return $this->hasMany(SurveyResponse::class);}
    public function recipients(){return $this->hasMany(SurveyRecipient::class);}
    public function contacts(){return $this->belongsToMany(Contact::class,'contact_survey')->withTimestamps();}
    public function leads(){return $this->belongsToMany(Lead::class,'lead_survey')->withTimestamps();}
    public function deals(){return $this->belongsToMany(Deal::class,'deal_survey')->withTimestamps();}
    public function accounts(){return $this->belongsToMany(Account::class,'account_survey')->withTimestamps();}
    public function files(){return $this->morphMany(CrmFile::class,'fileable');}
}
