const {Email} = require('vn-print');

module.exports = Self => {
    Self.remoteMethodCtx('osTicketReportEmail', {
        description: 'Sends the buyer waste email',
        accessType: 'WRITE',
        accepts: [],
        returns: {
            type: ['object'],
            root: true
        },
        http: {
            path: '/osticket-report-email',
            verb: 'POST'
        }
    });

    Self.osTicketReportEmail = async ctx => {
        const models = Self.app.models;
        const printConfig = await models.PrintConfig.findOne();

        const email = new Email('osticket-report', {
            recipient: printConfig.itRecipient,
            lang: ctx.req.getLocale()
        });

        return email.send();
    };
};