<?php

/**
 * This program is copyrighted by Franz Geffke (Softmax Co., Ltd.)
 */

namespace ones\oidc;

/**
 * Map ID token content to user from CIBA authentication
 * 
 * @param array $content
 */
function map_id_token_content($content) {
    return [
        'domain' => $content['domain'] ?? null,
        'sub' => $content['sub'] ?? null,
        'username' => $content['username'] ?? null,
        'username_without_domain' => $content['usernameWithoutDomain'] ?? null,
        'first_name' => $content['firstName'] ?? null,
        'last_name' => $content['lastName'] ?? null,
        'localized_first_name' => $content['localizedFirstName'] ?? null,
        'localized_last_name' => $content['localizedLastName'] ?? null,
        'identity_document_number' => $content['identityDocumentNumber'] ?? null,
        'identity_document_issue_date' => $content['identityDocumentIssueDate'] ?? null,
        'identity_document_expiry_date' => $content['identityDocumentExpiryDate'] ?? null,
        'date_of_birth' => $content['dateOfBirth'] ?? null,
        'email' => $content['email'] ?? null,
        'phone_number' => $content['phoneNumber'] ?? null
    ];
}

/**
 * Map consent content to user
 * 
 * @param array $content
 */
function map_consent_content($content) {
    // Transform the input array
    $transformedContent = [];
    foreach ($content as $item) {
        if (isset($item['key']) && isset($item['value'])) {
            $transformedContent[$item['key']] = $item['value'];
        }
    }

    // Map the transformed content to the desired output
    return [
        'domain' => null,
        'sub' => null,
        'username' => null,
        'username_without_domain' => null,
        'first_name' => $transformedContent['firstName'] ?? null,
        'last_name' => $transformedContent['lastName'] ?? null,
        'localized_first_name' => $transformedContent['localizedFirstName'] ?? null,
        'localized_last_name' => $transformedContent['localizedLastName'] ?? null,
        'identity_document_number' => $transformedContent['identityDocumentNumber'] ?? null,
        'identity_document_issue_date' => $transformedContent['identityDocumentIssueDate'] ?? null,
        'identity_document_expiry_date' => $transformedContent['identityDocumentExpiryDate'] ?? null,
        'date_of_birth' => $transformedContent['dateOfBirth'] ?? null,
        'email' => $transformedContent['email'] ?? null,
        'phone_number' => $transformedContent['phoneNumber'] ?? null
    ];
}

?>