<?php

namespace App\Models;

class PropertyPaymentMapping extends BaseModel
{
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'property_payment_mapping';
    protected $appends = ['paramsArray'];

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';

    protected $dateFormat = 'U';
    protected $guarded = [];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];

    public function getParamsArrayAttribute()
    {
        if(!is_null($this->params)) {
            return json_decode($this->params,1);
        } else {
            return null;
        }
    }

    public function paymentType()
    {
        return $this->hasOne('App\Models\PaymentType','id', 'payment_type_id');
    }

    public function propertyPaymentMappingInstallments()
    {
        return $this->hasMany('App\Models\PropertyPaymentInstallment','property_payment_mapping_id', 'id' )
            ->select('id', 'property_id', 'property_payment_mapping_id', 'installment', 'commission', 'status');
    }
}
