package WWW::MailboxOrg::API::Backup;

# ABSTRACT: Backup API

use Moo;
with 'WWW::MailboxOrg::Role::API';
use Params::ValidationCompiler qw( validation_for );
use Types::Standard qw( Str );

has client => (
    is       => 'ro',
    required => 1,
    weak_ref => 1,
);

my %validators = (
    list    => validation_for( params => { account => { type => Str, optional => 0 } } ),
    create  => validation_for( params => { account => { type => Str, optional => 0 } } ),
    restore => validation_for(
        params => {
            account => { type => Str, optional => 0 },
            backup  => { type => Str, optional => 0 },
        },
    ),
    delete => validation_for(
        params => {
            account => { type => Str, optional => 0 },
            backup  => { type => Str, optional => 0 },
        },
    ),
);


sub list {
    my ( $self, %params ) = @_;
    my $v = $validators{'list'};
    %params = $v->(%params) if $v;
    return $self->_rpc( 'backup.list', \%params );
}


sub create {
    my ( $self, %params ) = @_;
    my $v = $validators{'create'};
    %params = $v->(%params) if $v;
    return $self->_rpc( 'backup.create', \%params );
}


sub restore {
    my ( $self, %params ) = @_;
    my $v = $validators{'restore'};
    %params = $v->(%params) if $v;
    return $self->_rpc( 'backup.restore', \%params );
}


sub delete {
    my ( $self, %params ) = @_;
    my $v = $validators{'delete'};
    %params = $v->(%params) if $v;
    return $self->_rpc( 'backup.delete', \%params );
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

WWW::MailboxOrg::API::Backup - Backup API

=head1 VERSION

version 0.100

=head2 list

    my $backups = $api->backup->list(account => 'admin@example.com');

List backups. Required: C<account>.

=head2 create

    $api->backup->create(account => 'admin@example.com');

Create a backup. Required: C<account>.

=head2 restore

    $api->backup->restore(
        account => 'admin@example.com',
        backup  => 'backup-id',
    );

Restore a backup. Required: C<account>, C<backup>.

=head2 delete

    $api->backup->delete(
        account => 'admin@example.com',
        backup  => 'backup-id',
    );

Delete a backup. Required: C<account>, C<backup>.

=head1 SUPPORT

=head2 Issues

Please report bugs and feature requests on GitHub at
L<https://github.com/Getty/p5-www-mailboxorg/issues>.

=head2 IRC

Join C<#perl-help> on C<irc.perl.org> or message Getty directly.

=head1 CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

=head1 AUTHOR

Torsten Raudssus <getty@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
