<?php 
namespace PortalPeople\datadash\models;

use backend\models\Sysmodels;

class StaSearch extends \yii\base\Model
{

    private $classModel;
    public function __construct(array $config = [])
    {
        parent::__construct($config);
        $model = Sysmodels::find()->where(['name' => 'sta'])->one();
        $this->classModel = $model->source;
    }

    public function rules()
    {
        return [
            [['*'], 'safe'],
        ];
    }

    public function search($params)
    {
        $query = $this->classModel::find(); // Assuming Slt is the model representing the SLT data

        $dataProvider = new \yii\data\ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => $params['perPage'] ?? 20, // Set the number of items per page
            ],
            'sort' => [
                'defaultOrder' => ['_ID' => SORT_ASC], // Default sorting by ID descending
            ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // If validation fails, return an empty data provider
            $query->where('0=1');
            return $dataProvider;
        }

        // Add conditions bas
        return $dataProvider;
    }
}
