<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OpportunityAlert extends Model
{
    use HasFactory;
    protected $guarded = ["id"];
    protected $appends = ["alert_type_desc"];

    public function property() {
        return $this->belongsTo(Property::class);
    }

    public function user() {
        return $this->belongsTo(User::class);
    }

    public function mortgage() {
        return $this->belongsTo(MortgageInformation::class);
    }

    public function getCreatedAtAttribute($value) {
        return date("M d, Y h:i a", strtotime($value));
    }

    public function getAlertTypeDescAttribute(){
        if(!empty($this->alert_type)) {
            // change_loan_type
            // lower_rate_same_term
            // remove_mortgage_insurance
            // take_cash_out
            // lower_rate_not_same_term

            $array = [
                "change_loan_type" => "Change Loan Type",
                "lower_rate_same_term" => "Lower Rate Same Term",
                "remove_mortgage_insurance" => "Remove Mortgage Insurance",
                "take_cash_out" => "Take Cash Out",
                "lower_rate_not_same_term" => "Lower Rate Not Same Term"
            ];

            return $array[$this->alert_type];
        }

        return '';
    }
    
}
