<?php

namespace App\Models;

use App\Enums\SupportRequestStatusEnum;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id
 * @property int|null $user_id
 * @property string|null $user_type
 * @property string|null $name
 * @property string|null $email
 * @property string|null $phone
 * @property string $category
 * @property string $title
 * @property string $message
 * @property SupportRequestStatusEnum $status
 * @property int|null $handled_by
 * @property \Illuminate\Support\Carbon|null $resolved_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \App\Models\User|null $handler
 * @property-read \App\Models\User|null $user
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereCategory($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereHandledBy($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereResolvedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest whereUserType($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest withTrashed(bool $withTrashed = true)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportRequest withoutTrashed()
 * @mixin \Eloquent
 */
class SupportRequest extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'support_requests';

    protected $guarded = [
        'id',
    ];

    protected $fillable = [
        'user_id',
        'user_type',
        'name',
        'email',
        'phone',
        'category',
        'title',
        'message',
        'status',
        'handled_by',
        'resolved_at',
    ];

    protected $casts = [
        'status'      => SupportRequestStatusEnum::class,
        'resolved_at' => 'datetime',
        'created_at'  => 'datetime',
        'updated_at'  => 'datetime',
        'deleted_at'  => 'datetime',
    ];

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

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