import { Schema, Prop, SchemaFactory } from "@nestjs/mongoose";
import { Document, Types } from "mongoose";

export type UserSubscriptionDocument = UserSubscription & Document;

@Schema({ timestamps: true })
export class UserSubscription {
  @Prop({ type: Types.ObjectId, ref: "User" })
  userId: Types.ObjectId;

  @Prop({ type: Types.ObjectId, ref: "SubscriptionPlan" })
  planId: Types.ObjectId;

  @Prop({ required: true })
  productId: string;

  @Prop({ required: true })
  transactionId: string;
  // from Apple / Google purchase response

  @Prop({ default: null })
  originalTransactionId: string;

  @Prop({ default: null })
  currency: string;

  @Prop({ default: null })
  deviceType: string; // "ios" or "android"

  @Prop({ default: null })
  startDate: Date;

  @Prop({ default: null })
  expiryDate: Date;

  // @Prop({
  //   enum: ["active", "expired", "cancelled"],
  //   default: "active",
  // })
  // status: string;

  @Prop({ default: 0 })
  rewardedInvoicesCount: number;
}

export const UserSubscriptionSchema =
  SchemaFactory.createForClass(UserSubscription);
