const BaseModel = require('./BaseModel');
const { Model } = require('objection');

class Invite extends BaseModel {
  static get tableName() {
    return 'invites';
  }

  static get idColumn() {
    return 'id';
  }

  static get jsonSchema() {
    return {
      type: 'object',
      required: ['user_id', 'token', 'expires'],
      
      properties: {
        id: { type: 'integer' },
        user_id: { type: 'integer' },
        token: { type: 'string', minLength: 1 },
        expires: { type: 'string', format: 'date-time' },
        created: { type: 'string', format: 'date-time' },
      }
    };
  }

  static get relationMappings() {
    const User = require('./User');
    
    return {
      domainRelation: {
        relation: Model.BelongsToOneRelation,
        modelClass: User,
        join: {
          from: 'invites.user_id',
          to: 'users.id'
        }
      }
    };
  }
}

module.exports = Invite;