import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';

export type SuperAdminSettingsHistoryDocument = HydratedDocument<SuperAdminSettingsHistory>;

@Schema({ timestamps: true, versionKey: false })
export class SuperAdminSettingsHistory {
  @Prop({ default: 'default', index: true })
  scope!: string;

  @Prop({ required: true, trim: true, maxlength: 160 })
  updatedBy!: string;

  @Prop({ type: [String], default: [] })
  changedFields!: string[];

  @Prop({ type: Object, required: true })
  previousSettings!: Record<string, unknown>;

  @Prop({ type: Object, required: true })
  nextSettings!: Record<string, unknown>;

  @Prop({ default: '', trim: true, maxlength: 1000 })
  note!: string;
}

export const SuperAdminSettingsHistorySchema =
  SchemaFactory.createForClass(SuperAdminSettingsHistory);

SuperAdminSettingsHistorySchema.index({ scope: 1, createdAt: -1 });
