package Daje::Workflow::Activities::Authorities::Standard::Base;
use Mojo::Base 'Daje::Workflow::Common::Activity::Base', -base;
use v5.42;


# NAME
# ====
#
# Daje::Workflow::Activities::Authorities::Standard::Base - Daje Role creating activity base class,
# creates a new admin role and attach it to user and company
#
# SYNOPSIS
# ========
#
#
# DESCRIPTION
# ===========
#
# Daje::Workflow::Activities::Authorities::Standard::Base
#
# METHODS
# =======
#
#
#
#
# SEE ALSO
# ========
#
# Mojolicious, Mojolicious::Guides, https://mojolicious.org.
#
# LICENSE
# =======
#
# Copyright (C) janeskil1525.
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
# AUTHOR
# ======
#
# janeskil1525 E<lt>janeskil1525@gmail.com
#

use Daje::Database::Model::AuthoritiesRole;
use Daje::Database::Model::AuthoritiesFunctionPluginRole;
use Daje::Database::Model::AuthoritiesPluginRole;
use Daje::Database::Model::AuthoritiesFunctionPluginRolePermission;

sub createRole($self, $role, $standard) {

    return Daje::Database::Model::AuthoritiesRole->new(
        db => $self->db
    )->insert({
        name                      => $role,
        authorities_workflow_fkey => $self->context->{context}->{workflow}->{workflow_fkey},
        standard                  => $standard,
        companies_companies_fkey  => $self->context->{context}->{companies_fkey},
        description               => "Autogenerated system role",
    })->{data}->{authorities_role_pkey};

}

sub create_role_plugin($self, $authorities_role_pkey, $authorities_plugin_pkey, $description) {
    return Daje::Database::Model::AuthoritiesPluginRole->new(
        db => $self->db
    )->insert({
        authorities_role_fkey   => $authorities_role_pkey,
        authorities_plugin_fkey => $authorities_plugin_pkey,
        description             => $description
    })->{data}->{authorities_plugin_role_pkey};
}

sub create_function_plugin_role($self, $authorities_role_pkey, $authorities_function_pkey, $authorities_plugin_pkey, $description) {
    return Daje::Database::Model::AuthoritiesFunctionPluginRole->new(
        db => $self->db
    )->insert({
        authorities_role_fkey     => $authorities_role_pkey,
        authorities_function_fkey => $authorities_function_pkey,
        authorities_plugin_fkey   => $authorities_plugin_pkey,
        description               => $description,
    })->{data}->{authorities_function_plugin_role_pkey};
}

sub create_role_permissions($self, $authorities_permissions_pkey, $authorities_role_pkey, $authorities_function_pkey, $authorities_plugin_pkey) {
    Daje::Database::Model::AuthoritiesFunctionPluginRolePermission->new(
        db => $self->db
    )->insert({
        authorities_permissions_fkey    => $authorities_permissions_pkey,
        authorities_role_fkey           => $authorities_role_pkey,
        authorities_function_fkey       => $authorities_function_pkey,
        authorities_plugin_fkey         => $authorities_plugin_pkey,
    });
}
1;