import { EntitySchema } from '@mikro-orm/core';

export class AuthToken {
  id!: string;
  tenantId!: string;
  token!: string;
  name?: string;
  expiresAt?: Date;
  metadata?: Record<string, any>;
  createdAt!: Date;
  updatedAt!: Date;
}

export const AuthTokenSchema = new EntitySchema<AuthToken>({
  class: AuthToken,
  tableName: 'auth_tokens',
  properties: {
    id: {
      primary: true,
      type: 'uuid',
      default: 'uuid_generate_v4()',
    },
    tenantId: {
      type: 'string',
      nullable: false,
    },
    token: {
      type: 'string',
      nullable: false,
    },
    name: {
      type: 'string',
      nullable: true,
    },
    expiresAt: {
      type: 'date',
      nullable: true,
    },
    metadata: {
      type: 'json',
      nullable: true,
    },
    createdAt: {
      type: 'date',
      nullable: false,
      defaultRaw: 'now()',
    },
    updatedAt: {
      type: 'date',
      nullable: false,
      defaultRaw: 'now()',
    },
  },
});
