const {
    GraphQLString,
    GraphQLNonNull,
} = require('graphql');

const ResultType = require('../types/ResultType');
const { profileModel } = require('models');
const { getProfile } = require('core/profile');
const { MUTATION_PROFILE } = require('constants/permissions/values');

const mutation = {
    type: ResultType,
    args: {
        token: { type: new GraphQLNonNull(GraphQLString) },
    },
    resolve(_, { token }) {
        return new Promise(function (resolve, reject) {

            getProfile({ token, permission: MUTATION_PROFILE }).then(p => {

                profileModel.remove(p)
                    .then(() => resolve({}))
                    .catch(reject);

            }).catch(reject);

        });
    }
};

module.exports = mutation;
