<?php


namespace App\Models;
use Carbon\Carbon;
use Exception;

class PropertyProductOffer extends BaseModel
{

    protected $table = 'property_product_offer';
    protected $appends = ['detailArray','offerTimeFormatted','offerExpireTimeFormatted'];

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

    protected $dateFormat = 'U';

    public function getDetailArrayAttribute()
    {
        $parameters = null;
        if (!is_null($this->detail)) {
            $parametersArray = json_decode($this->detail, 1);
            if (is_array($parametersArray)) {
                $parameters = $parametersArray;
            }
        }

        return $parameters;
    }


    public function getOfferTimeFormattedAttribute()
    {
        try {
            return Carbon::parse($this->offer_date)->format('d.m.Y H:i:s');
        } catch (Exception $e) {
            return null;
        }
    }

    public function getOfferExpireTimeFormattedAttribute()
    {
        try {
            return Carbon::parse($this->offer_expire_date)->format('d.m.Y H:i:s');
        } catch (Exception $e) {
            return null;
        }
    }
}
