<?php
/**
* @package CembraPay Payment Gateway for WooCommerce
* @author  Adrian Emil Tudorache
* @license GPL-2.0+
* @link    https://www.tudorache.me/
*/

if ( ! defined( 'ABSPATH' ) ) {
	header( 'Status: 403 Forbidden' );
	header( 'HTTP/1.1 403 Forbidden' );
	exit;
}

/**
 * Create the required database tables on plugin activation.
 * 
 * @return void
 */
function cembrapay_install(): void {

    global $wpdb;

    $charset_collate = $wpdb->get_charset_collate();

    $logs = "CREATE TABLE " . CEMBRA_LOGS_TABLE . " (
        id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
		order_id INT(11),
        first_name VARCHAR(255),
        last_name VARCHAR(255),
        req_type VARCHAR(255),
        proc_status VARCHAR(255),
        request LONGTEXT,
        response LONGTEXT,
        datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (id)
    ) $charset_collate;";

    if( ! function_exists( 'dbDelta' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    }

	$tables = array(
		$logs
	);

	foreach( $tables as $table ) {
		dbDelta( $table );
	}

    $byjuno_opts = get_option( 'woocommerce_byjuno_settings' );
    if( $byjuno_opts ) {
        update_option( 'woocommerce_cembrapay_legacy_settings', array(
            'use_order_id_prefix' => $byjuno_opts['use_order_id_prefix'],
            'order_id_prefix'     => $byjuno_opts['order_id_prefix'],
        ) );
    }

    $translations_exists = get_option( 'cembrapay_field_translations' );
    
    if( ! $translations_exists ) {

        $translations = array(
            'title' => array(
                'de' => 'CembraPay Rechnung',
                'fr' => 'Facture CembraPay',
                'it' => 'CembraPay fattura'
            ),
            'description' => array(
                'de' => 'Die Rechnung wird von CembraPay AG zugestellt. Im Rahmen der Kaufabwicklung wird eine Kreditprüfung durchgeführt.',
                'fr' => 'Les factures seront envoyées par CembraPay AG. Une vérification de crédit sera effectuée dans le cadre du processus d’achat.',
                'it' => 'Le fatture vengono inviate da CembraPay SA. Durante il processo di pagamento verrà effettuato un controllo del credito.'
            ),
            'invoice_type_intro_text' => array(
                'de' => 'Rechnung erhalten:',
                'fr' => 'Recevoir la facture:',
                'it' => 'Ricevere la fattura:'
            ),
            'instructions' => array(
                'de' => 'Um Fortzufahren benötigen wir diese Informationen:',
                'fr' => 'Pour pouvoir continuer, nous avons besoin de ces informations:',
                'it' => 'Abbiamo bisogno di queste informazioni per continuare:'
            ),
            'unavailable' => array(
                'de' => 'Der Zahlungsanbieter hat die Zahlung abgelehnt. Bitte versuchen Sie eine andere Zahlungsmethode.',
                'fr' => 'L\'institution de crédit a refusé le paiement. Veuillez essayer un autre moyen de paiement.',
                'it' => 'L\'istituto di credito ha rifiutato il pagamento. Si prega di provare un altro metodo di pagamento.'
            ),
            'gender_field_label' => array(
                'de' => 'Gender DE',
                'fr' => 'Gender FR',
                'it' => 'Gender IT'
            ),
            'gender_field_label_female' => array(
                'de' => 'Female DE',
                'fr' => 'Female FR',
                'it' => 'Female IT'
            ),
            'gender_field_label_male' => array(
                'de' => 'Male DE',
                'fr' => 'Male FR',
                'it' => 'Male IT'
            ),
            'gender_field_label_other' => array(
                'de' => 'Other DE',
                'fr' => 'Other FR',
                'it' => 'Other IT'
            ),
            'birthdate_field_day_label' => array(
                'de' => 'Tag',
                'fr' => 'Jour',
                'it' => 'Giorno'
            ),
            'birthdate_field_month_label' => array(
                'de' => 'Monat',
                'fr' => 'Mois',
                'it' => 'Mese'
            ),
            'birthdate_field_year_label' => array(
                'de' => 'Jahr',
                'fr' => 'Année',
                'it' => 'Anno'
            ),
            'birthdate_field_label' => array(
                'de' => 'Geburtsdatum',
                'fr' => 'Date de naissance',
                'it' => 'Data di nascita'
            ),
            'salutation_field_label' => array(
                'de' => 'Anrede',
                'fr' => 'Dénomination',
                'it' => 'Appellativo'
            ),
            'salutation_field_label_female' => array(
                'de' => 'Frau',
                'fr' => 'Madame',
                'it' => 'Signora'
            ),
            'salutation_field_label_male' => array(
                'de' => 'Herr',
                'fr' => 'Monsieur',
                'it' => 'Signor'
            ),
            'salutation_field_label_other' => array(
                'de' => 'keine Angabe',
                'fr' => 'aucune indication',
                'it' => 'nessuna indicazione'
            ),
            'installments_6_template' => array(
                'de' => 'CembraPay ZERO 6in6',
                'fr' => 'CembraPay ZERO 6in6',
                'it' => 'CembraPay ZERO 6in6'
            ),
            'company_reg_field_label' => array(
                'de' => 'UID Nummer',
                'fr' => 'Numéro UID',
                'it' => 'Numero UID'
            ),
            'cembrapay_invoice_template' => array(
                'de' => 'CembraPay Rechnung',
                'fr' => 'CembraPay facture',
                'it' => 'CembraPay fattura'
            ),
            'invoice_via_email' => array(
                'de' => 'via E-Mail (ohne Gebühr) an: {email}',
                'fr' => 'par e-mail (sans frais supplémentaires): {email}',
                'it' => 'via e-mail (gratuitamente): {email}'
            ),
            'invoice_via_post' => array(
                'de' => 'in Papierform via Post (gegen Gebühr von CHF 4.25) an: {address}',
                'fr' => 'sur papier par courrier (tarif de CHF 4.25): {address}',
                'it' => 'in forma cartacea per posta (costo di 4.25 CHF): {address}'
            ),
            'installments_intro_text' => array(
                'de' => 'Bitte wählen Sie die Anzahl der Monatsraten aus:',
                'fr' => 'Veuillez sélectionner le nombre de mensualités:',
                'it' => 'Selezioni il numero delle rate mensili:'
            ),
            'installments_full_template' => array(
                'de' => 'CembraPay Einzelrechnung',
                'fr' => 'CembraPay facture unique',
                'it' => 'CembraPay fattura singola'
            ),
            'installments_3_template' => array(
                'de' => 'CembraPay ZERO 3in3',
                'fr' => 'CembraPay ZERO 3in3',
                'it' => 'CembraPay ZERO 3in3'
            ),
            'installments_4_template' => array(
                'de' => 'CembraPay ZERO 4in4',
                'fr' => 'CembraPay ZERO 4in4',
                'it' => 'CembraPay ZERO 4in4'
            ),
            'installments_12_template' => array(
                'de' => 'CembraPay ZERO 12in12',
                'fr' => 'CembraPay ZERO 12in12',
                'it' => 'CembraPay ZERO 12in12'
            ),
            'installments_24_template' => array(
                'de' => 'CembraPay ZERO 24in24',
                'fr' => 'CembraPay ZERO 24in24',
                'it' => 'CembraPay ZERO 24in24'
            ),
            'installments_36_template' => array(
                'de' => 'CembraPay ZERO 36in36',
                'fr' => 'CembraPay ZERO 36in36',
                'it' => 'CembraPay ZERO 36in36'
            ),
            'installments_48_template' => array(
                'de' => 'CembraPay ZERO 48in48',
                'fr' => 'CembraPay ZERO 48in48',
                'it' => 'CembraPay ZERO 48in48'
            )
        );

        update_option( 'cembrapay_field_translations', $translations );

    }

}
?>
