package Cpanel::Easy::Test;

# cpanel10 - Cpanel/Easy/Test.pm              Copyright(c) 2005-2007 cPanel, Inc.
#                                                            All rights Reserved.
# copyright@cpanel.net                                          http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited

use base 'Cpanel::Easy';

{

    sub new {
        my ( $class, $args_ref ) = @_;
        my $self = ref $class ? $class : bless {}, $class;

        # directories used in but not having their own arg
        mkdir '/var/cpanel/easy/';
        mkdir '/var/cpanel/easy/test/';
        mkdir '/var/cpanel/easy/test/profile/';
        mkdir '/var/cpanel/easy/test/profile/custom/';
        mkdir '/usr/local/cpanel/logs/easy';
        mkdir '/usr/local/cpanel/logs/easy/test/';
        mkdir '/home/cpeasytest/';

        $self->{'version'}                      = '3.0.1';
        $self->{'pid_file'}                     = $args_ref->{'pid_file'} || '/var/run/easytest.pid';
        $self->{'base_dir'}                     = $args_ref->{'base_dir'} || '/usr/local/test';
        $self->{'log_file'}                     = $args_ref->{'log_file'} || '/usr/local/cpanel/logs/easy/test/build.' . time();
        $self->{'state_file'}                   = $args_ref->{'state_file'} || '/var/cpanel/easy/test/state.yaml';
        $self->{'prefs_file'}                   = $args_ref->{'prefs_file'} || '/var/cpanel/easy/test/prefs.yaml';
        $self->{'path_md5_dir'}                 = $args_ref->{'path_md5_dir'} || '/var/cpanel/easy/test/path_md5';
        $self->{'profile_main'}                 = $args_ref->{'profile_main'} || '/var/cpanel/easy/test/profile/_main.yaml';
        $self->{'profile_default'}              = $args_ref->{'profile_default'} || '/var/cpanel/easy/test/profile/custom/cpanel_default.yaml';
        $self->{'profile_prev'}                 = $args_ref->{'profile_prev'} || '/var/cpanel/easy/test/profile/_prev.yaml';
        $self->{'profile_custom_dir'}           = $args_ref->{'profile_custom_dir'} || '/var/cpanel/easy/test/profile/custom';
        $self->{'opt_mod_src_dir'}              = $args_ref->{'opt_mod_src_dir'} || '/home/cpeasytest/src';
        $self->{'opt_mod_custom_dir'}           = $args_ref->{'opt_mod_custom_dir'} || '/var/cpanel/easy/test/custom_opt_mods';
        $self->{'rawenv_dir'}                   = $args_ref->{'rawenv_dir'} || '/var/cpanel/easy/test/rawenv';
        $self->{'rawopts_dir'}                  = $args_ref->{'rawopts_dir'} || '/var/cpanel/easy/test/rawopts';
        $self->{'variations'}                   = [];
        $self->{'state_file_needs_redone_file'} = $args_ref->{'state_file_needs_redone_file'} || '/etc/easy.test.state_file_needs_redone';
        $self->{'report_host'}                  = $args_ref->{'report_host'} || 'buildap.cpanel.net';
        $self->{'report_uri'}                   = $args_ref->{'report_uri'} || 'buildap-submit.pl';

        # this tells us where to look in the object's path to generate the setup stash
        $self->{'state_config'} = {

            # Item.pm is the main item, Item/ contains any specific opt mods that 'recursive partial override'-ify any opt-mods in '.'
            # in UI they can only choose one
            'main_vers' => [qw(5 6)],
            'main_name' => 'Test',        # Cpanel::Easy::
            'ignore'    => ['OptMod'],    # 'Item' = Ignore Item/ and Item.pm, Utils and UI are always treated like they are in this list
                                          # Cpanel::Easy::* name spaces to "include" in state hash as well
            'include'   => [
                qw(
                  Cpanel::Easy::Test_IncludeA
                  Cpanel::Easy::Test_IncludeB
                  )
            ],
        };

        $self->ensure_valid_obj_key( 'param_obj', 'param',  $args_ref, 'Cpanel::CPAN::Getopt::Param' );
        $self->ensure_valid_obj_key( 'ui_obj',    'isa_ui', $args_ref, 'Cpanel::Easy::Apache::UI::CLI' );

        # available prefs with their default values:
        $self->{'default_prefs'} = {
            'verbose'       => 1,
            'notify_cpanel' => 1,
        };

        $self->{'_'}{'test_src_path'} = $self->{'opt_mod_src_dir'} . '/' . $self->{'state'}{'optmods'}{'Cpanel::Easy::Test'}{'src_cd2'};

        $self->SUPER::new($args_ref);

        return $self;
    }

    sub _create_backup {
        shift->print_to_log_and_screen("\t\tCREATING BACKUP\n");
    }

    sub _post_httpd_conf_check {
        shift->print_to_log_and_screen("\t\tPOST HTTPD CONF CHECK\n");
    }

    sub _restore_backup_if_needed {
        shift->print_to_log_and_screen("\t\tRESTORING BACKUP IF NEEDED\n");
    }

    sub _cpanelsync {
        shift->print_to_log_and_screen("\t\tCPANELSYNC IF NEEDED\n");
    }

    sub report_errors {
        my ($self) = @_;
        my $note = $self->{'_'}{'prefs'}{'notify_cpanel'} ? 'notifying' : 'not notifying';

        # format and post $self->{'_'}{'error'} etc
        shift->print_to_log_and_screen("\t\t$note CPANEL OF ERRORS\n");
    }
}

1;
