<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class UserAction extends Model
{
    protected $fillable = [
        'user_id',
        'type',
        'data'
    ];

    protected $casts = [
        'user_id' => 'integer',
        'data' => 'array',
    ];

    protected $appends = [
        'display_type',
    ];

    protected function displayType(): Attribute
    {
        return Attribute::make(
            get: fn () => match ($this->type) {
                'flight_booked' => 'Flight Booked',
                'flight_cancelled' => 'Flight Cancelled',
                'flight_updated' => 'Flight Updated',
                'flight_imported' => 'Flight Imported from FR24',
                'flight_logged' => 'Flight Logged',
                'flight_deleted' => 'Flight Deleted',
                'flight_departing' => 'Flight Departed',
                'flight_arriving' => 'Flight Landed',
                default => 'Unknown Action'
            }
        );
    }


    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

}
