<?php

/**
 * CGBetterUploads API
 *
 * @package CGBetterUploads
 */

namespace CGBetterUploads;

/**
 * A class to represent a file created via the yousend it interface.
 * This object adds extra data to the upload object to identify who is sending and receiving the file, and other data.
 *
 * @property-read string $subject The subject of the file.
 * @property-read string $to_addr The email address of the receiver.
 * @property-read string $from_name The name of the individual sending the file.
 * @property-read string $from-addr The email address of the individual sending the file.
 */
class YouSenditUpload extends Upload
{
    /**
     * @ignore
     */
    public function __get( string $key )
    {
        switch( $key ) {
        case 'subject':
            return $this->summary;

        case 'to_addr':
        case 'from_name':
            return $this->get_extra_val($key);

        case 'from_addr':
            return $this->author;

        default:
            return parent::__get( $key );
        }
    }

    /**
     * Adjust the to address of the object
     *
     * @internal
     * @param string $addr The email address
     * @return YouSendItUpload
     */
    public function withToAddress( string $addr = null ) : YouSendItUpload
    {
        return $this->set_extra_val( 'to_addr', $addr );
    }

    /**
     * Adjust the to address of the object
     *
     * @internal
     * @param string $addr The email address
     * @return YouSendItUpload
     */
    public function withFromAddress( string $addr = null ) : YouSendItUpload
    {
        return $this->set_extra_val( 'from_addr', $addr );
    }

    /**
     * Adjust the sender name.
     *
     * @internal
     * @param string $name
     * @return YouSenditUpload
     */
    public function withFromName( string $name = null ) : YouSendItUpload
    {
        return $this->set_extra_val( 'from_name', $name );
    }

} // class
