<?php
namespace Microservices\www\Config\Common\Private\Sql\DataModification\POST;

/**
 * API Query config
 * php version 8.3
 *
 * @category  API_Query_Config
 * @package   Microservices
 * @author    Ramesh N. Jangid (Sharma) <polygon.co.in@gmail.com>
 * @copyright © 2026 Ramesh N. Jangid (Sharma)
 * @license   MIT https://opensource.org/license/mit
 * @link      https://github.com/shames11/Microservices
 * @since     Class available since Release 1.0.0
 */

use Microservices\App\Constant;
use Microservices\App\DatabaseServerDataType;
use Microservices\App\Env;
use Microservices\DatabaseTable;

return [
	'__SQL__' => "INSERT INTO `{$this->httpObject->httpReqData['active']['customerData']['customer_user_table']}` SET __SET__",
	'__SET__' => [
		[
			'column' => 'customer_user_contact_name',
			'activeDataKey' => 'payload',
			'activeDataKeySubKey' => 'firstname'
		],
		[
			'column' => 'customer_user_contact_person',
			'activeDataKey' => 'payload',
			'activeDataKeySubKey' => 'lastname'
		],
		[
			'column' => 'customer_user_contact_email_address',
			'activeDataKey' => 'payload',
			'activeDataKeySubKey' => 'email'
		],
		[
			'column' => 'customer_user_username',
			'activeDataKey' => 'payload',
			'activeDataKeySubKey' => 'username'
		],
		[
			'column' => 'customer_user_password_hash',
			'activeDataKey' => 'function',
			'activeDataKeySubKey' => function(
				$activeData,
				$payload
			) {
				if (isset($payload['password'])) {
					return password_hash(
						password: $payload['password'],
						algo: PASSWORD_DEFAULT
					);
				}
			}
		],
		[
			'column' => 'customer_user_cidr',
			'activeDataKey' => 'custom',
			'activeDataKeySubKey' => '0.0.0.0/0'
		],
		[
			'column' => DatabaseTable::$customerUserGroupPrimaryKey,
			'activeDataKey' => 'custom',
			'activeDataKeySubKey' => '1'
		],
	],
	'__INSERT-ID__' => 'registration:id',
	'__PRIMARY-KEY__' => DatabaseTable::$customerUserPrimaryKey,
	'__SUB-CONFIG__' => [
		'address' => [
			'__SQL__' => 'INSERT INTO `address` SET __SET__',
			'__SET__' => [
				[
					'column' => DatabaseTable::$customerPrimaryKey,
					'activeDataKey' => 'customerData',
					'activeDataKeySubKey' => DatabaseTable::$customerPrimaryKey
				],
				[
					'column' => DatabaseTable::$customerUserPrimaryKey,
					'activeDataKey' => '__INSERT-ID__',
					'activeDataKeySubKey' => 'registration:id'
				],
				[
					'column' => 'address',
					'activeDataKey' => 'payload',
					'activeDataKeySubKey' => 'address'
				]
			],
			'__INSERT-ID__' => 'address:id',
			'__PRIMARY-KEY__' => DatabaseTable::$addressPrimaryKey,
			'__PAYLOAD-TYPE__' => 'Array',
			'__MAX-PAYLOAD-OBJECT__' => 2
		]
	],
	'__FOLLOW-SQL_CONFIG-THREAD__' => Constant::$TRUE,
	'__PAYLOAD-TYPE__' => 'Object',
	'idempotentWindow' => 10
];
