<?php

namespace App\Models;

use CodeIgniter\Model;

class SavedSearchModel extends Model
{
    protected $table         = 'saved_searches';
    protected $useTimestamps = false;
    protected $allowedFields = ['agency_id', 'user_id', 'name', 'search_type', 'filters', 'alert_enabled'];
    protected $casts         = ['filters' => 'json'];

    public function forUser(int $userId, string $type): array
    {
        return $this->where('user_id', $userId)->where('search_type', $type)->orderBy('created_at', 'DESC')->findAll();
    }
}
