package LATMOS::Accounts::Bases::OCHelper::Address;

# $Id: OCHelper.pm 2932 2010-08-10 17:19:21Z nanardon $

use strict;
use warnings;
use base qw(LATMOS::Accounts::Bases::OCHelper);
use LATMOS::Accounts::Utils;
use LATMOS::Accounts::Log;

=head1 NAME

LATMOS::Accounts::Bases::OCHelper - Object creation helper

=head1 DESCRIPTION

This module is designed to be subclassed.

=head1 FUNCTIONS

=cut

# just return status, $info is reference
sub _step {
    my ($self, $info) = @_;

    if ($info->{step} == 0) {
        $info->{name}{ask} = 0;
        foreach ($self->base->list_canonical_fields($self->otype, 'w')) {
            /^oalias$/ and next;
            /^template$/ and next;
            push(@{$info->{ask}}, $_);
        }
        $info->{step} = 1;
        return 'NEEDINFO';
    } elsif ($info->{step} == 1) {
        if (! $info->{name}{content} ) {
            my $random = LATMOS::Accounts::Utils::genpassword();
            $info->{name}{content} = $info->{contents}{user} . '-' . $random;
        }
        if ($self->base->create_c_object($self->otype,
                $info->{name}{content},
                %{$info->{contents} || {}},
            )) {
            return 'CREATED';
        } else {
            return 'ERROR';
        }
    } else {
        return undef;
    }
}

1;

__END__

=head1 SEE ALSO

L<LATMOS::Accounts::Bases>, L<LATMOS::Accounts::Bases::Objects>

=head1 AUTHOR

Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2012 CNRS SA/CETP/LATMOS

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=cut
