<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Opportunity extends Model
{
    use HasFactory, SoftDeletes;
    protected $table = "opportunities";
    protected $fillable  = [
        'id',
        'start_date',
        'end_date',
        'description',
        'stage_id',
        'customer_id',
        'user_id',
        'source_id',
        'contact_method_id',
        'customer_references_id',
        'property_id',
        'entity_status',
    ];

    protected $hidden = [
        'updated_at',
        'deleted_at',
        'created_by',
        'updated_by',
        'deleted_by',
    ];


    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function stage()
    {
        return $this->belongsTo(Stage::class);
    }

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

    public function source()
    {
        return $this->belongsTo(Source::class);
    }

    public function contact_method()
    {
        return $this->belongsTo(ContactMethod::class);
    }

    public function customer_reference()
    {
        return $this->belongsTo(CustomerReference::class);
    }

    public function property()
    {
        return $this->belongsTo(Property::class);
    }

    public function activities()
    {
        return $this->hasMany(Activity::class);
    }

    public function sales()
    {
        return $this->hasMany(Sales::class);
    }

    public function procedures(){
        return $this->belongsToMany(
            Procedure::class,
            'opportunity_procedures',
            'opportunity_id',
            'procedure_id',
        );
    }

    public function quotes()
    {
        return $this->hasMany(Quote::class, 'opportunity_id');
    }
}
