<?php

namespace App\Http\Controllers;

use App\Models\ClauseArg;
use Illuminate\Http\Request;
use App\Models\Clause;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid;
use App\Models\StatTree;
use App\Models\StatTreeLine;
use App\Models\StatTreeLineClause;

class ClauseArgController extends Controller
{

    // eps
    public function create(Request $request) {
        $clauseArg = new ClauseArg();
        $nextId = DB::select("select nextval('clause_arg_id_seq')");
        $clauseArg->id = $nextId[0]->nextval;
        $clauseArg->clause_id = $request->input('clauseId');
        $clauseArg->arg_text = $request->input('argText');
        $clauseArg->field_type = $request->input('fieldType');
        $clauseArg->save();
        return $this->pass();
    }
    public function update(Request $request) {
        $clauseArg = ClauseArg::where('id', $request->input('id'))->first();
        if(!$clauseArg) return $this->fail('Clause arg not found!');
        $clauseArg->arg_text = $request->input('argText');
        $clauseArg->field_type = $request->input('fieldType');
        $clauseArg->save();
        return $this->pass();
    }
    public function remove(Request $request) {
        $clauseArg = ClauseArg::where('id', $request->input('id'))->first();
        if(!$clauseArg) return $this->fail('Clause arg not found!');
        DB::select("delete from clause_arg where id = {$clauseArg->id}");
        return $this->pass();
    }

}
