<?php
session_start();
require_once "../../config.php";
require_once "../../../validation.php";
require_once "../../../Helper.php";
require_once '../../database1.php';
require_once "../../check_admin.php";


class valueAdd extends database{
	public function index($data)
	{
		return $this->insert('tb_product_subcategory_values_filter', $data);
	}
}

if(!isset($_POST['name']) || !isset($_POST['id']))
{
	http_response_code(400);
	echo json_encode(array('error_text' => 'No input found'));
	exit;
}

$data['name'] = $name = $_POST['name'];
$data['product_subcategory_filter_id'] = $id = $_POST['id'];

if(trim($name) == '')
{
    http_response_code(400);
	echo json_encode(array('error_text' => 'Name is required'));
	exit;
}

if(trim($id) == '')
{
    http_response_code(400);
	echo json_encode(array('error_text' => 'Filter not mentioned'));
	exit;
}

$helper = new Helper();
$validation = new validation();





$unsetFields = array('cl_id','cl_deleted_at');
$data = $validation->unsetValues($unsetFields, $data);
$data = $validation->setColumnPrefix($data);

$obj = new valueAdd();
$res = $obj->index($data);
if(!$res)
{
	http_response_code(401);
	echo json_encode(array('error_text' => 'Something Went Wrong'));
	exit;
}

session_start();
$_SESSION['error_message'] = 'Values Updated Successfully';
$_SESSION['error_type'] = 'success';

http_response_code(200);
echo json_encode(array('message' => 'Values Updated Successfully'));
exit;