package Daje::Helper::Languages::InsertKeys;
use Mojo::Base -base, -signatures;
use v5.42;

use Data::Dumper;

has 'db';


sub process($self, $keys) {

    my $keys_stmt = qq{
            INSERT INTO languages_translation_keys
                    (plugin, field, languages_types_fkey, key, comment)
            VALUES (?, ?, (SELECT languages_types_pkey FROM languages_types WHERE type = ?), ?, ?)
                ON CONFLICT (plugin, field, languages_types_fkey, key) DO UPDATE SET moddatetime = NOW()
            RETURNING languages_translation_keys_pkey
    };

    my $transl_stmt = qq{
            INSERT INTO languages_translations
                (languages_lan_fkey, languages_translation_keys_fkey, translation)
            VALUES ((SELECT languages_lan_pkey FROM languages_lan WHERE iso_code = ?), ?, ?)
                ON CONFLICT (languages_lan_fkey, languages_translation_keys_fkey)
            DO UPDATE SET translation = ?, moddatetime = NOW()
    };

    my $length = scalar @{$keys};
    for (my $i = 0; $i < $length; $i++) {
        my $language = @{$keys}[$i];
        my $languages_translation_keys_pkey = $self->db->query(
            $keys_stmt, (
                $language->{plugin}, $language->{field}, $language->{type}, $language->{key}, $language->{comment}
            )
        )->hash->{languages_translation_keys_pkey};

        $self->db->query(
            $transl_stmt, (
                'ENG', $languages_translation_keys_pkey, $language->{translation}, $language->{translation}
            )
        );
    }
}

1;

#################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################

=head1 NAME

Daje::Helper::Languages::InsertKeys


=head1 DESCRIPTION

pod generated by Pod::Autopod - keep this line to make pod updates possible ####################


=head1 REQUIRES

L<Data::Dumper> 

L<v5.42> 

L<Mojo::Base> 


=head1 METHODS

=head2 process($self,

 process($self,();


=cut

