/**
 * Request API Models
 * Models for license request management
 */

import { ApprovalStatus } from './approval.models';

export type RequestType = 'NEW_LICENSE' | 'RENEWAL' | 'AMENDMENT' | 'MODIFICATION' | 'CANCELLATION';
export type RequestStatus = 'DRAFT' | 'SUBMITTED' | 'IN_REVIEW' | 'PENDING_RESUBMISSION' | 'APPROVED' | 'REJECTED' | 'REVOKED' | 'CANCELLED';

export interface CreateRequestDto {
  applicantName: string;
  applicantPhone?: string;
  businessName?: string;
  requestType: RequestType;
  workflowId?: string;
  workflowCode?: string;
  metadata?: Record<string, any>;
  tokenId?: number;
}

export interface UpdateRequestDto {
  businessName?: string;
  description?: string;
  metadata?: Record<string, any>;
}

export interface RequestResponseDto {
  id: string;
  requestNumber: string;
  applicantId: string;
  requestType: RequestType;
  status: RequestStatus;
  currentStageId?: string;
  metadata: Record<string, any>;
  blockchainTxHash?: string;
  tokenId?: string;
  createdAt: string;
  updatedAt: string;
  submittedAt?: string;
  approvedAt?: string;
}

export interface DocumentDetailDto {
  id: string;
  docType: string;
  originalFilename: string;
  currentVersion: number;
  currentHash: string;
  minioBucket: string;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

export interface ApprovalDetailDto {
  id: string;
  departmentId: string;
  status: ApprovalStatus;
  remarks?: string;
  reviewedDocuments: string[];
  createdAt: string;
  updatedAt: string;
  invalidatedAt?: string;
  invalidationReason?: string;
}

export interface RequestDetailResponseDto {
  id: string;
  requestNumber: string;
  applicantId: string;
  requestType: RequestType;
  status: RequestStatus;
  currentStageId?: string;
  metadata: Record<string, any>;
  blockchainTxHash?: string;
  tokenId?: string;
  documents: DocumentDetailDto[];
  approvals: ApprovalDetailDto[];
  createdAt: string;
  updatedAt: string;
  submittedAt?: string;
  approvedAt?: string;
}

export interface PaginatedRequestsResponse {
  data: RequestResponseDto[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
  hasNextPage: boolean;
}

export interface RequestFilters {
  status?: RequestStatus;
  requestType?: RequestType;
  applicantId?: string;
  requestNumber?: string;
  startDate?: string;
  endDate?: string;
  page?: number;
  limit?: number;
  sortBy?: 'createdAt' | 'updatedAt' | 'requestNumber' | 'status';
  sortOrder?: 'ASC' | 'DESC';
}
