import { Schema } from "mongoose";
import { applyIdTransform, registerModel, stringId } from "../schema";

const RefreshTokenSchema = new Schema(
  {
    _id: stringId,
    userId: { type: String, ref: "User", required: true, index: true },
    tokenHash: { type: String, required: true, unique: true },
    expiresAt: { type: Date, required: true, index: true },
    revokedAt: { type: Date, default: undefined },
  },
  { timestamps: { createdAt: true, updatedAt: false } },
);

applyIdTransform(RefreshTokenSchema);

export const RefreshToken = registerModel("RefreshToken", RefreshTokenSchema);
