module.exports = (sequelize, DataTypes) => {
    let StaffApplications = sequelize.define('StaffApplications', {
        username: {
            type: DataTypes.STRING(191),
            unique: false,
            required: true,
            validate: {
                is: {
                    args: [/^[a-zA-Z0-9_]*$/],
                    msg: 'Username can only contain numbers and letters'
                },
                len: {
                    args: [3, 16],
                    msg: 'username must be between 3 and 16 characters'
                },
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('username must be a string')
                    }
                },
                containsNoBlankCharacters (val) {
                    if(/\s/g.test(val)) {
                        throw new sequelize.ValidationError('username can\'t contain blank characters')
                    }
                }
            }
        },
        email: {
            type: DataTypes.TEXT,
            required: true,
            validate: {
                isEmail: {
                    args: true,
                    msg: 'Email is not formatted correctly'
                },
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('email must be a string')
                    }
                },
                len: {
                    args: [5, 100],
                    msg: 'Email must be between 5 and 100 characters'
                }
            }
        },
        whyWork: {
            type: DataTypes.TEXT,
            required: true,
            validate: {
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('Answer must be a string')
                    }
                },
                len: {
                    args: [100, 1000],
                    msg: 'Why do you want to work for Kaverti must be less than 1000 characters but more then 100 characters'
                }
            }
        },
        otherForm: {
            type: DataTypes.TEXT,
            required: true,
            validate: {
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('Answer must be a string')
                    }
                },
                len: {
                    args: [0, 64],
                    msg: 'Other must be less than 64 characters'
                }
            }
        },
        experience: {
            type: DataTypes.TEXT,
            required: true,
            validate: {
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('Past Experience must be a string')
                    }
                },
                len: {
                    args: [0, 1000],
                    msg: 'Past experience must be less than 1000 characters'
                }
            }
        },
        suggestions: {
            type: DataTypes.TEXT,
            required: false,
            validate: {
                isString (val) {
                    if(typeof val !== 'string') {
                        throw new sequelize.ValidationError('Suggestions must be a string')
                    }
                },
                len: {
                    args: [0, 1000],
                    msg: 'Suggestions must be less than 1000 characters'
                }
            }
        },
        dob: {
            type: DataTypes.DATE,
            required: true,
            validate: {
                isDate: {
                    args: true,
                    msg: 'Date of birth is not formatted correctly, try and use the date picker.'
                },
                len: {
                    args: [3, 1000],
                    msg: 'Date of birth must be less than 1000 characters but more then 3, and in a date format.'
                }
            }
        },
        selectedOption: {
            type: DataTypes.TEXT,
            required: true,
            values: ['other','moderator','modeler', 'devsite', 'devgame'],
            validate: {
                isIn: {
                    args: [['other','moderator','modeler', 'devsite', 'devgame']],
                    msg: "Answer can only be one of the pre-defined options"
                },
                len: {
                    args: [0, 50],
                    msg: 'Answer must be less than 50 characters'
                }
            }
        }
    })

    return StaffApplications
}