<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MontessoriMembershipApplication extends Model
{
    protected $table = 'montessori_membership_applications';
    public $timestamps = false;
    protected $dateFormat = 'U';
    protected $guarded = ['id'];

    protected $casts = [
        'form_data' => 'array',
    ];

    /**
     * Accessor to automatically decode JSON form_data
     */
    public function getFormDataAttribute($value)
    {
        if (is_string($value)) {
            return json_decode($value, true);
        }
        return $value;
    }

    /**
     * Mutator to automatically encode form_data as JSON
     */
    public function setFormDataAttribute($value)
    {
        if (is_array($value)) {
            $this->attributes['form_data'] = json_encode($value, JSON_UNESCAPED_UNICODE);
        } else {
            $this->attributes['form_data'] = $value;
        }
    }

    /**
     * Get formatted created date
     */
    public function getCreatedAtFormattedAttribute()
    {
        return date('Y-m-d H:i:s', $this->created_at);
    }
}
