import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Shipment } from './shipment.schema';
import mongoose from 'mongoose';
import { ADMIN, USER } from 'src/utils/constants';

@Schema({ timestamps: true })
export class Map_Shipment_Attachment {
  @Prop({ type: mongoose.Types.ObjectId })
  shipment_id: Shipment;

  @Prop({ default: '' })
  type: string;

  @Prop({ default: '' })
  name: string;

  @Prop({ default: '' })
  file_name: string;

  @Prop({ default: '' })
  mime_type: string;

  @Prop({ default: '' })
  path: string;

  @Prop({ default: '' })
  base_url: string;

  @Prop({ default: '' })
  original_name: string;

  @Prop({ enum: [USER, ADMIN] })
  uploaded_by: string;
}

export const Map_Shipment_Attachment_Schema = SchemaFactory.createForClass(
  Map_Shipment_Attachment,
);
export type Map_Shipment_Attachment_Document = Map_Shipment_Attachment &
  Document;

// Supports barcode/receiving_slip lookup: filter by shipment_id + name, sort by latest
Map_Shipment_Attachment_Schema.index({ shipment_id: 1, name: 1, createdAt: -1 });
