<?php

namespace App\Models;

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

class Sales extends Model
{
    use HasFactory, SoftDeletes;
    protected $table = "sales";
    protected $fillable  = [
        'id',
        'social_reason',
        'nit',
        'creation_date',
        'status',
        'payment_method',
        'delivery_date',
        'amount',
        'initial_fee',
        'percentage_initial_fee',
        'is_payment_initial_fee',
        'discount',
        'opportunity_id',
        'quote_id',
        'entity_status',
        'confirmation_signature'
    ];

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

    public function payment_plans()
    {
        return $this->hasMany(PaymentPlans::class);
    }

    public function opportunity()
    {
        return $this->belongsTo(Opportunity::class);
    }

    public function property(){
        return $this->belongsToMany(
            Property::class,
            'sale_details',
            'sale_id',
            'property_id',
            )->withPivot('price', 'price_it', 'price_contrato');
    }
    public function quote(){
        return $this->belongsTo(Quote::class);
    }

}
