module.exports = Self => {
    Self.remoteMethod('addDropOff', {
        description: 'Add a dropOff note in a ticket',
        accessType: 'WRITE',
        accepts: [{
            arg: 'ticketFk',
            type: 'number',
            required: true,
            description: 'ticket ID'
        }, {
            arg: 'note',
            type: 'string',
            required: true,
            description: 'note text'
        }],

        http: {
            path: `/addDropOff`,
            verb: 'post'
        }
    });

    Self.addDropOff = async(ticketFk, note, options) => {
        const models = Self.app.models;
        const myOptions = {};

        if (typeof options == 'object')
            Object.assign(myOptions, options);

        const observationTypeDropOff = await models.ObservationType.findOne({
            where: {code: 'dropOff'}
        }, myOptions);

        await models.TicketObservation.create({
            ticketFk: ticketFk,
            observationTypeFk: observationTypeDropOff.id,
            description: note

        }, myOptions);
    };
};