import { ApiProperty } from '@nestjs/swagger';
import { RequestStatus } from '../enums/request-status.enum';
import { RequestType } from '../enums/request-type.enum';
import { ApprovalStatus } from '../../../common/enums';

export class DocumentDetailDto {
  @ApiProperty()
  id: string;

  @ApiProperty()
  docType: string;

  @ApiProperty()
  originalFilename: string;

  @ApiProperty()
  currentVersion: number;

  @ApiProperty()
  currentHash: string;

  @ApiProperty()
  minioBucket: string;

  @ApiProperty()
  isActive: boolean;

  @ApiProperty()
  createdAt: Date;

  @ApiProperty()
  updatedAt: Date;
}

export class ApprovalDetailDto {
  @ApiProperty()
  id: string;

  @ApiProperty()
  departmentId: string;

  @ApiProperty({
    enum: ApprovalStatus,
  })
  status: ApprovalStatus;

  @ApiProperty({
    nullable: true,
  })
  remarks: string | null;

  @ApiProperty({
    type: [String],
  })
  reviewedDocuments: string[];

  @ApiProperty()
  createdAt: Date;

  @ApiProperty()
  updatedAt: Date;

  @ApiProperty({
    nullable: true,
  })
  invalidatedAt: Date | null;

  @ApiProperty({
    nullable: true,
  })
  invalidationReason: string | null;
}

export class RequestDetailResponseDto {
  @ApiProperty()
  id: string;

  @ApiProperty()
  requestNumber: string;

  @ApiProperty()
  applicantId: string;

  @ApiProperty({
    enum: RequestType,
  })
  requestType: RequestType;

  @ApiProperty({
    enum: RequestStatus,
  })
  status: RequestStatus;

  @ApiProperty({
    nullable: true,
  })
  currentStageId: string | null;

  @ApiProperty()
  workflowId: string;

  @ApiProperty({
    nullable: true,
  })
  workflowCode?: string;

  @ApiProperty()
  currentStepIndex: number;

  @ApiProperty({
    nullable: true,
  })
  assignedDepartment?: string;

  @ApiProperty({
    type: Object,
  })
  metadata: Record<string, any>;

  @ApiProperty({
    type: Object,
  })
  formData: Record<string, any>;

  @ApiProperty({
    nullable: true,
  })
  blockchainTxHash: string | null;

  @ApiProperty({
    nullable: true,
  })
  tokenId: string | null;

  @ApiProperty({
    type: [DocumentDetailDto],
  })
  documents: DocumentDetailDto[];

  @ApiProperty({
    type: [ApprovalDetailDto],
  })
  approvals: ApprovalDetailDto[];

  @ApiProperty()
  createdAt: Date;

  @ApiProperty()
  updatedAt: Date;

  @ApiProperty({
    nullable: true,
  })
  submittedAt: Date | null;

  @ApiProperty({
    nullable: true,
  })
  approvedAt: Date | null;

  @ApiProperty({
    nullable: true,
    type: Object,
  })
  workflow?: {
    id: string;
    code: string;
    name: string;
    steps: any[];
  };

  @ApiProperty({
    nullable: true,
    type: Object,
  })
  applicant?: {
    id: string;
    email: string;
    name: string;
    walletAddress: string;
  };
}
