<?php

namespace App\Models\Crm;

use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Complaint extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'customer_id', 'type', 'content', 'images',
        'status', 'handler_id', 'handle_result', 'handle_at',
    ];

    protected function casts(): array
    {
        return [
            'type' => 'integer',
            'images' => 'array',
            'status' => 'integer',
            'handle_at' => 'datetime',
        ];
    }

    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

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