/**
 * Author:  Thomas GUERY
 *
 * Anonymise une base de données.
 * Created: 12/04/2024
 */
Delimiter //
Drop Procedure If Exists CRYPT_DATABASE //
Create Procedure CRYPT_DATABASE(
)
Begin
    bdelent_main: Begin
    End;

    cryptdb_contacts: Begin
        UPDATE CONTACTS SET CONTACTS_NOTE = 'XXXXXXX';
    End ;

    cryptdb_contacts_business: Begin
        UPDATE CONTACTS_BUSINESS SET CONTACTS_BUSINESS_COMPANY_NAME = concat(substr(CONTACTS_BUSINESS_COMPANY_NAME,1,3),'XXXXXXX');
        UPDATE CONTACTS_BUSINESS SET CONTACTS_BUSINESS_BRAND_NAME = concat(substr(CONTACTS_BUSINESS_BRAND_NAME,1,3),'XXXXXXX');
        UPDATE CONTACTS_BUSINESS SET CONTACTS_BUSINESS_SIRET = null;
    End ;

    cryptdb_contacts_individial: Begin
            UPDATE CONTACTS_INDIVIDUAL SET CONTACTS_INDIVIDUAL_FIRST_NAME = concat(substr(CONTACTS_INDIVIDUAL_FIRST_NAME,1,3),'XXXXXXX');
            UPDATE CONTACTS_INDIVIDUAL SET CONTACTS_INDIVIDUAL_LAST_NAME = concat(substr(CONTACTS_INDIVIDUAL_LAST_NAME,1,3),'XXXXXXX');
            UPDATE CONTACTS_INDIVIDUAL SET CONTACTS_INDIVIDUAL_BIRTH_NAME = concat(substr(CONTACTS_INDIVIDUAL_BIRTH_NAME,1,3),'XXXXXXX');
            UPDATE CONTACTS_INDIVIDUAL SET CONTACTS_INDIVIDUAL_BIRTH_DAY = null;
    End ;

    cryptdb_contacts_emails: Begin
        UPDATE CONTACTS_EMAILS SET CONTACTS_EMAILS_EMAIL = 'XXXX@XXX.fr';
        -- UPDATE CONTACTS_EMAILS SET Concat(Substring(CONTACTS_EMAILS_EMAIL,1,3),'XXXXXXX',Substring(CONTACTS_EMAILS_EMAIL,LENGTH(CONTACTS_EMAILS_EMAIL)-1,1)
    End ;

    cryptdb_accounts: Begin
        UPDATE ACCOUNTS SET ACCOUNTS_NOTES = 'XXXXXXX';
    End ;

    cryptdb_contacts_iban: Begin
        UPDATE CONTACTS_RIB_IBAN SET CONTACTS_RIB_IBAN_IBAN = 'XXXXXXX';
        UPDATE CONTACTS_RIB_IBAN SET CONTACTS_RIB_IBAN_BIC = 'XXXXXXX';
        UPDATE CONTACTS_RIB_IBAN SET CONTACTS_RIB_IBAN_PREFERENCE = 00000000000;
        UPDATE CONTACTS_RIB_IBAN SET CONTACTS_RIB_IBAN_TRASHED = 00000000000;
    End ;

    cryptdb_contacts_adresses: Begin
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_LINE_1 = 'XXXXXXX';
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_LINE_2 = 'XXXXXXX';
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_LINE_3 = 'XXXXXXX';
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_LINE_4 = 'XXXXXXX';
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_ZIP_CODE = 'XXXXXXX';
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_CITY = concat(substr(CONTACTS_ADDRESSES_CITY,1,3),'XXXXXXX');
        UPDATE CONTACTS_ADDRESSES SET CONTACTS_ADDRESSES_TRASHED = 0000000000;
    End ;

End //
Delimiter ;