package Platform::Edit_Profile_Request;
use strict;
use warnings;
use base 'Platform::DBI';

__PACKAGE__->table('edit_profile_request');
__PACKAGE__->sequence('edit_profile_request_edit_profile_request_seq');
__PACKAGE__->columns( Primary => 'edit_profile_request' );
__PACKAGE__->columns( Essential => qw / 
	account
	requested_at
	archived
/ );

__PACKAGE__->has_a( account => 'Platform::Account' );
__PACKAGE__->has_a( requested_at => 'Class::Date' );

__PACKAGE__->set_sql(by_token => <<';');
SELECT edit_profile_request FROM edit_profile_request
WHERE MD5(CONCAT(edit_profile_request, requested_at)) = ?
;

sub get_token {
  my ($self) = @_;
  my $sth = $self->db_Main->prepare("SELECT MD5(CONCAT(edit_profile_request, requested_at)) AS token FROM edit_profile_request WHERE edit_profile_request = ?");
  
  $sth->execute($self->id);

  my ($result) = $sth->fetchall_hash();

  return $result->{token};
}

sub is_expired {
  my ($self) = @_;

  return $self->requested_at < (Class::Date->now - '1D');
}