<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Http\Resources\StoreTypeResource;
use Illuminate\Http\Request;
use App\Http\Resources\SubCategoryResource;
use App\Models\Store;
use App\Models\StoreType;
use App\Models\SubCategory;

class StoreTypeController extends Controller
{
    public function getList(Request $request)
    {
        $storetype = StoreType::query()->whereStatus(1);

        $per_page = config('constant.PER_PAGE_LIMIT');
        if( $request->has('per_page') && !empty($request->per_page)){
            if(is_numeric($request->per_page))
            {
                $per_page = $request->per_page;
            }
            if($request->per_page == -1 ){
                $per_page = $storetype->count();
            }
        }

        $storetype = $storetype->orderBy('id', 'asc')->paginate($per_page);

        $items = StoreTypeResource::collection($storetype);
        $status = 200;

        $response = [
            'status'        => $status,
            'pagination'    => json_pagination_response($items),
            'data'          => $items,
        ];

        return json_custom_response($response);
    }


    public function getDetail(Request $request)
    {
        $id = $request->id;
        $storetype = StoreType::where('id',$id)->first();

        if(empty($storetype))
        {
            $message = __('message.not_found_entry',[ 'name' => __('message.storetype') ]);
            return json_message_response($message,400);
        }

        $storetype_detail = new StoreTypeResource($storetype);

        $response = [
            'data' => $storetype_detail
        ];

        return json_custom_response($response);
    }


}
