<?php

namespace App\Http\Controllers;

use App\Models\OptionValue;
use Illuminate\Http\Request;
use App\Models\OptionKey;

class OptionController extends Controller
{

    public function option_keys(Request $request,$classify_id) {
        $classify_id = $request->route("classify_id");
        if($classify_id) {
            $options = OptionKey::with("optionValues")->where("classify_id", $classify_id)->get()->toArray();
            return Response()->json([
                "status" => 0,
                "data" => $options
            ]);

        }
    }

    public function option_key(Request $request, $id) {

        $option_key_id = $request->route("id");
        if($option_key_id) {
            $option_value = OptionKey::with("optionValues")->find($option_key_id);
            return Response()->json([
                "status" => 0,
                "data" => $option_value
            ]);
        }
    }

    public function option_value(Request $request, $id) {

        $option_value_id = $request->route("id");
        if($option_value_id) {
            $option_value = OptionValue::with("optionKey")->find($option_value_id);
            return Response()->json([
                "status" => 0,
                "data" => $option_value
            ]);
        }
    }
}
