import {Realm} from 'realm'; import {AMServerConnectionInfo, AMServerMetadata} from "amnet-shared"; export class AMServer extends Realm.Object implements AMServerConnectionInfo, AMServerMetadata { _id!: Realm.BSON.ObjectId; apiVersion: number; gameId?: string; serverName: string; serverAddress: string; lastUsed: Date; createdAt: Date; preferredCardIdFormat?: "idm" | "access" | null; get shareUrl() { return `http://card.ppc.moe/#/servers/add?address=${encodeURIComponent(this.serverAddress)}`; } static generate(serverAddress: string) { return { _id: new Realm.BSON.ObjectId(), apiVersion: 0, serverName: "New Server", serverAddress: serverAddress, createdAt: new Date(), lastUsed: null } } static schema: Realm.ObjectSchema = { name: "server", primaryKey: "_id", properties: { _id: "objectId", apiVersion: {type: "int", default: 0}, gameId: {type: "string", optional: true}, serverAddress: "string", serverName: {type: "string", default: "New Server", indexed: "full-text"}, createdAt: {type: "date", default: new Date()}, lastUsed: {type: "date", optional: true, indexed: true} } }; }