<?php

namespace App\Http\Controllers\Admin;

use App\Models\Termsandconditions;
use App\Services\Admin\termsandconditionServices;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Validator;

class TermsController extends Controller
{
    public function index()
    {
        $terms_condition = Termsandconditions::all()->toArray();

        return view('Admin.pages.manage_cms.manage_terms.manage_terms', compact('terms_condition'));
    }
    // public function edit($id)
    // {
    //     $terms = Termsandconditions::find($id)->toArray();
    //     return view('Admin.pages.manage_cms.manage_terms.manage_terms_edit', compact('terms'));
    // }
    public function edit($id)
    {

        $terms = Termsandconditions::find($id);
        //   dd($terms);
        return view('Admin.pages.manage_cms.manage_terms.manage_terms_edit', compact('terms'));
    }

    public function update(Request $request)
    {

        $validated = $request->validate([

            'article_des' => 'required', // Add validation for article_des
        ]);
        $update = Termsandconditions::find($request->custom_id);
        $update->message = $request->input('article_des');
        $update->save();
        return response()->json(['success' => true, 'status' => 200]);
    }


    public function editTerms_rest($id)
    {
        $edit_terms_rest = Termsandconditions::find($id);
        // return $edit_terms_rest;
        return view('Admin.pages.manage_cms.manage_terms.manage_terns_edit_rest', compact('edit_terms_rest'));
    }

    public function update_rest(Request $request)
    {
        $validated = $request->validate([
            'termsrest_des' => 'required',
        ]);
        $update_rest = Termsandconditions::find($request->termRest_id);
        $update_rest->message = $request->input('termsrest_des');
        $update_rest->save();
        return response()->json(['success' => true, 'status' => 200]);
    }
}
