import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import mongoose, { Document } from 'mongoose';
import { User } from '../../users/users.model';
import { StorageFile } from 'src/modules/storage/storage.schema';

export type ImageHistoryDocument = ImageHistory & Document;


@Schema({ timestamps: true })
export class ImageHistory {
	_id: mongoose.Types.ObjectId;

	@Prop({
		type: mongoose.Schema.Types.ObjectId,
		required: [true, 'User is required'],
		index: true,
		ref: 'User',
	})
	user: User;

	@Prop({ type: String})
	prompt: string;

	@Prop({ type: [StorageFile], default: []})
	images: StorageFile[];

	@Prop({ type: String, default: 'loading', enum: ['loading', 'success', 'failed', 'blocked']})
	status: 'loading' | 'success' | 'failed' | 'blocked';

	@Prop({ type: String, enum: ['text2img', 'img2img', 'imgUpscale']})
	type: 'text2img' | 'img2img' | 'imgUpscale';

	@Prop({ type: String})
	style_preset: string;

	@Prop({ type: Number})
	samples: number;

	@Prop({ type: String, select: false })
	model: string;

	@Prop({ type: String, select: false })
	finalPrompt: string;

	@Prop({
        type: Object,
        required: false,
        default: {},
		select: false,
    })
    filterResult: {
        [key: string]: string | boolean;
    };

	createdAt: Date;
	updatedAt: Date;
}

export const ImageHistorySchema = SchemaFactory.createForClass(ImageHistory);