const Contract = {

    create : function( p )
    {
        Object.assign( this, p.getAll() );
    },


    getContracteeData : function( key )
    {
        if ( key )
        {
            if ( this.contractee_data_js && this.contractee_data_js.hasOwnProperty( key ) )
            {
                return this.contractee_data_js[ key ];
            }
            else
            {
                return null;
            }
        }
        else
        {
            return this.contractee_data_js;
        }
    },

    getProfileFirstName : function()
    {
        let fn = 'Unbekannt';

        if ( this.profile_data_js && this.profile_data_js.hasOwnProperty( 'first_name' ) )
        {
            fn = this.profile_data_js.first_name;
        }

        return fn;
    },

    getProfileLastName : function()
    {
        let ln = 'Unbekannt';

        if ( this.profile_data_js && this.profile_data_js.hasOwnProperty( 'last_name' ) )
        {
            ln = this.profile_data_js.last_name;
        }

        return ln;
    },

    getProfileId : function()
    {
        if ( this.profile_id )
        {
            return this.profile_id;
        }
        else
        {
            return null;
        }
    },

    getType : function()
    {
        return this.type;
    },

    isFlatrate : function()
    {
        return ( this.type === 'flatrate' );
    },

    getCurrentPriceFactor : function()
    {
        return this.current_price_factor / 100 ;
    },

    getMaxPriceFactor : function()
    {
        return this.max_price_factor / 100;
    },

    getPrice : function()
    {
        return this.price / 100;
    },

    getPricePayed : function()
    {
        return this.price_payed / 100;
    },

    getClaimAmount : function()
    {
        return ( this.price - this.price_payed ) / 100;
    },

    isPaymentDue : function()
    {
        let mPaymentDueDate = moment( this.payment_due_date, 'YYYY-MM-DD' ),
            mNow = moment();

        return ( mPaymentDueDate.isBefore( mNow ) );
    },

    getState : function()
    {
        return this.state;
    },

    getMomentPaymentDueDate : function()
    {
        return moment( this.payment_due_date, 'YYYY-MM-DD' );
    },

    getMomentStartDate : function()
    {
        return moment( this.start_date, 'YYYY-MM-DD' );
    },

    getMomentEndDate : function()
    {
        return moment( this.end_date, 'YYYY-MM-DD' );
    },

    getMomentCreationDate : function()
    {
        return moment( new Date( this.created_dt.date ) );
    },

    isArchived : function()
    {
        return ( this.state === 'archive' );
    },

    destroy : function()
    {

    }
};

export { Contract };