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

export type ImportLogDocument = ImportLog & Document;

export interface ImportError {
  type: "grn" | "rotation" | "transfer";
  groupKey: string;
  message: string;
}

export interface ImportSummary {
  grnCreated: number;
  grnUpdated: number;
  rotationCreated: number;
  rotationUpdated: number;
  transferCreated: number;
  transferUpdated: number;
  errorCount: number;
}

@Schema({ collection: "import_logs", timestamps: false })
export class ImportLog {
  @Prop({ required: true })
  declare importedBy: string;

  @Prop({ required: true })
  declare importedAt: string;

  @Prop({ required: true })
  declare fileName: string;

  @Prop({ type: Object, required: true })
  declare summary: ImportSummary;

  @Prop({ type: [Object], default: [] })
  declare errors: ImportError[];
}

export const ImportLogSchema = SchemaFactory.createForClass(ImportLog);
