<?php

namespace Yajny\Controller;

use App\Http\Controllers\Controller;

use Yajny\Models\Brand;

class BrandCtrl extends Controller
{

    /**
     * @param $brandids
     * @return array
     */
    public static function getBrandsById($brandids)
    {
        if( count($brandids) == 0 ) return [];
        // orderby Feilds to be Implemented
        return  Brand::whereIn('id',$brandids)->orderByRaw('FIELD(id,'. implode($brandids) .')')->get();
    }

    /**
     * @param $brandids
     * @return mixed
     */
    public static function getBrandsByIdApi($brandids)
    {
        // orderby Feilds to be Implemented
        return  Brand::whereIn('id',$brandids)->selectRaw( Brand::colSelect())->get();
    }

    /**
     * @return mixed
     */
    public static function getAllBrandsGrouped()
    {
        $collection = Brand::orderBy('name')->get();
       
       return $collection->groupBy(function ($item) {
            $char = mb_substr(mb_strtoupper($item->name), 0, 1); return ( is_numeric($char) ) ? '0-9' : $char;
        })->sortKeys();

    }


}
