package Google::RestApi::GmailApi1::Attachment;

our $VERSION = '2.0.0';

use Google::RestApi::Setup;

sub new {
  my $class = shift;
  state $check = compile_named(
    message => HasApi,
    id      => Str,
  );
  return bless $check->(@_), $class;
}

sub api {
  my $self = shift;
  my %p = @_;
  my $uri = "attachments";
  $uri .= "/$self->{id}" if $self->{id};
  $uri .= "/$p{uri}" if $p{uri};
  delete $p{uri};
  return $self->message()->api(%p, uri => $uri);
}

sub get {
  my $self = shift;

  LOGDIE "Attachment ID required for get()" unless $self->{id};

  return $self->api();
}

sub attachment_id { shift->{id}; }
sub message { shift->{message}; }

1;

__END__

=head1 NAME

Google::RestApi::GmailApi1::Attachment - Attachment object for Gmail messages.

=head1 SYNOPSIS

 # Get an attachment from a message
 my $att = $message->attachment(id => 'att_id');
 my $data = $att->get();
 # $data->{data} contains base64url-encoded attachment body

=head1 DESCRIPTION

Represents an attachment on a Gmail message. Supports retrieving attachment
data.

=head1 METHODS

=head2 get()

Gets attachment data. Returns a hashref with 'data' (base64url-encoded body)
and 'size' fields.

=head2 attachment_id()

Returns the attachment ID.

=head2 message()

Returns the parent Message object.

=head1 AUTHORS

=over

=item

Robin Murray mvsjes@cpan.org

=back

=head1 COPYRIGHT

Copyright (c) 2019-2026 Robin Murray. All rights reserved.

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
