<?php

namespace App\Models;

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

class Property extends Model
{
    use HasFactory, SoftDeletes;
    protected $table = "properties";
    protected $fillable  = [
        'id',
        'title',
        'code',
        'location',
        'latitud',
        'longitud',
        'surface',
        'description',
        'delevery_date',
        'status',
        'precio_por_m2',
        'property_type',
        'final_price',
        'base_price',
        'percentage_initial_fee',
        'initial_fee',
        'payment_method',
        'entity_status',
        'property_type_id',
        'project_id',
    ];


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


    public function benefits(){
        return $this->belongsToMany(Benefits::class,'property_benefits','property_id','benefit_id');
    }

    public function features(){
        return $this->belongsToMany(Feature::class,'property_features','property_id','feature_id');
    }

    public function financings()
    {
        return $this->hasOne(Financing::class);
    }

    public function departament(){
        return $this->hasOne(Department::class);
    }

    public function parking(){
        return $this->hasOne(Parking::class);
    }

    public function land(){
        return $this->hasOne(Land::class);
    }

    public function house(){
        return $this->hasOne(Houses::class);
    }

    public function office(){
        return $this->hasOne(Office::class);
    }

    public function opportunities()
    {
        return $this->hasOne(Opportunity::class);
    }

    public function project()
    {
        return $this->belongsTo(Project::class);
    }

    public function property_type()
    {
        return $this->belongsTo(TypeProperty::class);
    }

    public function sale(){
        return $this->belongsToMany(
            Sales::class,
            'sale_details',
            'sale_id',
            'property_id',
            )->withPivot('price');
    }

    public function quote(){
        return $this->belongsToMany(
            sales::class,
            'quote_details',
            'quote_id',
            'property_id',
            )->withPivot('price', 'price_it', 'price_contrato');
    }
}
