import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import type { HydratedDocument } from "mongoose";
import mongoose from "mongoose";
import type { Project } from "./project.schema.js";

@Schema()
export class User {
  @Prop({ unique: true })
  username!: string;

  @Prop()
  passwordHash!: string;

  @Prop({
    type: [{ type: mongoose.Schema.Types.ObjectId, ref: "Project" }],
    default: [],
  })
  projects!: Project[];
}

export type UserDocument = HydratedDocument<User>;
export const UserSchema = SchemaFactory.createForClass(User);
