<?php

namespace app\admin\controller\client;

use app\controller\Curd;
use app\model\SysConfig;
use support\Request;
use support\Response;

class AppParamsController extends Curd
{
    public function __construct()
    {
        $this->model = new SysConfig();
    }

    public function select(Request $request): Response
    {
        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
        $where['config_category'] = 'APP';
        $query = $this->doSelect($where, $field, $order);
        return $this->doFormat($query, $format, $limit);
    }

    protected function insertInput(Request $request): array
    {
        $data = $this->inputFilter($request->post());
        $data['config_category'] = 'APP';
        if (empty($data['config_value_json'])){
            $data['config_value_json'] = '[]';
        }
        return $data;
    }
}