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_at'],
      
      properties: {
        id: { type: 'integer' },
        user_id: { type: 'string', minLength: 1, maxLength: 255 },
        token: { type: 'string', minLength: 1 },
        expires_at: { type: 'string', format: 'date-time' },
        created_at: { 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;