/**
 * Role.js
 *
 * @description :: A model definition represents a database table/collection.
 * @docs        :: https://sailsjs.com/docs/concepts/models-and-orm/models
 */


module.exports = {
    tableName: 'utilisateurs',

    attributes: {
        /* id: {
         type: 'number',
         //columnName: 'id',
         unique: true,
         autoIncrement: true,
         primaryKey: true,
         //required: true,
         columnType: 'integer',
     },*/
        login: {
            type: 'string',
            columnName: 'login',
            required: true,
            unique: true

        },
        codeVerif: {
            type: 'string',
            columnName: 'code_verif',
            allowNull: true,

        },

        codeUser: {
            type: 'string',
            columnName: 'code_user',
            allowNull: true

        },
        codeEcole: {
            type: 'string',
            columnName: 'code_ecole',
            required: true,

        },

        nom: {
            type: 'string',
            columnName: 'nom',
            required: true,

        },

        email: {
            type: 'string',
            columnName: 'email',
            allowNull: true

        },

        indicatif1: {
            type: 'string',
            columnName: 'indicatif1',
            allowNull: true,
            //columnType: 'bigint'

        },

        telephone1: {
            type: 'string',
            columnName: 'telephone1',
            allowNull: true,
            //columnType: 'bigint'
        },
        indicatif2: {
            type: 'string',
            columnName: 'indicatif2',
            allowNull: true,
            //columnType: 'bigint'

        },

        telephone2: {
            type: 'string',
            columnName: 'telephone2',
            allowNull: true,
            //columnType: 'bigint'
        },
        typeUser: {
            type: 'string',
            columnName: 'type_user',
            required: true,

        },

        password: {
            type: 'string',
            columnName: 'password',
            allowNull: true,
            //required: true,

        },

        isUpdate: {
            type: 'boolean',
            columnName: 'isUpdate',
            defaultsTo: false,
            //required: true,

        },
        desactiverCompte: {
            type: 'boolean',
            defaultsTo: false,
            columnName: 'desactiver_compte',
        },

        permissions: {
            collection: 'permission',
            via: 'owners'
        },
        tokens: {
            collection: 'token',
            via: 'owner'
        },
        resetToken: {
            type: 'string',
            columnName: 'reset_token',
            allowNull: true,

        },
        resetTokenExpiresAt: {
            type: 'string',
            columnName: 'reset_token_expiresat',
            allowNull: true,

        },
        isUpdatePending: {
            type: 'boolean',
            columnName: 'is_update_pending',
            defaultsTo: false
        },
        lastLoginAt: {
            type: 'number',
            columnName: 'last_login',
            defaultsTo: 0
        },
        pendingNotifications: {
            collection: 'pendingnotification',
            via: 'user'
        },
        notificationHistory: {
            collection: 'notificationhistory',
            via: 'user'
        },
    },
    customToJSON: function () {
        return _.omit(this, ['codeVerif', 'photo', 'password', 'isUpdate'])
    }

};

