<?php

namespace App\Http\Controllers\Api\mini;

use App\Models\Spec;
use Illuminate\Http\Request;

class SpecController extends BaseController
{
    protected $model;

    public function __construct()
    {
        $this->model = new Spec();
    }

    public function get(Request $request)
    {
        if($request->input('type') == 'drop_menu') {
            $items = $this->model;
            if($request->input('device_name_ids')) {
                $device_name_ids = $request->input('device_name_ids');
                $device_name_ids = array_filter($device_name_ids, function($item) {
                    return $item;
                });
                if(count($device_name_ids) > 0) {
                    $items = $items->whereIn('device_name_id', $device_name_ids);
                }
            }
            $items = $items->select('name as text', 'id as value')->get();
            $items = $items->prepend(collect(['text' => '型号规格', 'value' => '']));
            return $this->success(['data' => $items]);
        }
        $items = $this->model->get();
        return $this->success(['data' => $items]);
    }

    public function getStat(Request $request)
    {

    }
}
