const Component = require(`vn-print/core/component`);
const emailBody = new Component('email-body');

module.exports = {
    name: 'payment-update',
    async serverPrefetch() {
        this.payMethod = await this.fetchPayMethod(this.id);

        if (!this.payMethod)
            throw new Error('Something went wrong');
    },
    computed: {
        accountAddress: function() {
            return this.payMethod.iban.slice(-4);
        },
    },
    methods: {
        fetchPayMethod(id) {
            return this.findOneFromDef('payMethod', [id]);
        }
    },
    components: {
        'email-body': emailBody.build(),
    },
    props: {
        id: {
            type: Number,
            required: true,
            description: 'The client id'
        }
    }
};