import DB from "../database.js";
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model.js";
import { ObjectId } from "mongodb";
import { v4 } from "uuid";

export interface IRefreshToken extends ModelDataBase {
   token: string;
   user: ObjectId;
   client: ObjectId;
   permissions: ObjectId[];
   validTill: Date;
   valid: boolean;
}

const RefreshToken = DB.addModel<IRefreshToken>({
   name: "refresh_token",
   versions: [
      {
         migration: () => { },
         schema: {
            token: { type: String },
            user: { type: ObjectId },
            client: { type: ObjectId },
            permissions: { type: Array },
            validTill: { type: Date },
            valid: { type: Boolean },
         },
      },
   ],
});

export default RefreshToken;
