import { NameDTO } from "@/record-management/components/hooks/useTemplate";

export interface RecordListDto {
  id: string;
  createdAt: string;
  updatedAt: string;
  fileInfo: any | null;
  referenceNumber: string | null;
  preferredLanguage: "English" | "Amharic" | string;
  submittedDate: string | null;
  dispatchedDate: string | null;
  statusKey: "Draft" | "Submitted" | "Dispatched" | string;
  initiationType: "self" | "delegated" | string;
  isUploadCompleted: boolean | null;
  initiatorId: string;
  userId: string | null;
  recordTypeKey: "internal" | "external" | string;
  unitId: string;
}

export interface Name {
  am: string;
  en: string;
}

export interface FileInfo {
  fileName: string;
  contentType: string;
  originalname: string;
  size?: number;
  bucket?: string;
}

export interface RecordAttachmentDto {
  id: string;
  recordContentId: string;
  isCurrent: boolean;
  uploadedSuccessfully: boolean;
  fileInfo: FileInfo;
  createdAt: string;
  updatedAt: string;
}

export interface PositionDto {
  id: string;
  name: Name;
  key: string;
  rank?: number;
  parentPositionId: string | null;
  unitId: string;
  organizationId: string;
  projectId: string | null;
  positionTypeId: string | null;
  createdAt: string;
  updatedAt: string;
  deletedAt?: string | null;
}

export interface ReceiverPositionDto {
  id: string;
  recordContentId: string;
  positionId: string;
  order: number;
  position: PositionDto;
  createdAt: string;
  updatedAt: string;
}

export interface EmployeeDto {
  createdAt: string;
  updatedAt: string;
  id: string;
  isCurrent: boolean;
  status: string;
  name: Name;
  organizationId: string;
  unitId: string;
  userId: string;
}

export interface EmployeePositionDto {
  createdAt: string;
  updatedAt: string;
  id: string;
  isDelegate: boolean;
  isCurrent: boolean;
  status: string;
  startDate: string | null;
  amharicStartDate: string | null;
  endDate: string | null;
  amharicEndDate: string | null;
  unitId: string;
  delegatorId: string | null;
  employeeId: string;
  positionId: string;
  delegateePositionId: string | null;
  delegationLetterId: string | null;
  position: PositionDto;
  employee: EmployeeDto;
}

export interface ReceiverEmployeeDto {
  createdAt: string;
  updatedAt: string;
  id: string;
  recordContentId: string;
  employeePositionId: string;
  order: number;
  employeePosition: EmployeePositionDto;
}

export interface UnitDto {
  id: string;
  name: Name;
  key: string;
  organizationId: string;
  parentUnitId: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface CCsDto {
  positionId?: string; // Only for internal
  unitId: string;
  type: "internal" | "external";
  isForYourReference?: boolean;
  value?: string; // For MultiSelect
  label?: string; // For display
  position?: {
    name: {
      en: string;
      am?: string;
    };
  };
  unit?: {
    name: {
      en: string;
      am?: string;
    };
  };
  employeePositionId: string | null;
  employeePosition: {
    employee?: {
      name: { am: string; en: string };
    };
  };
}

export interface RecordContentDto {
  letterName: string;
  nonSmartOfficeReceiverCCs: string[];
  nonSmartOfficeReceivers: string[];
  nonSmartReceivers?: {
    id: string;
    name: string;
    isCc: boolean;
    isForYourReference: boolean;
    prefix?: string | null;
    suffix?: string | null;
    order?: number | null;
    createdAt?: string;
    updatedAt?: string;
  }[];
  id: string;
  version: number;
  isCurrent: boolean;
  date: string | null;
  subject: string;
  prefix: string | null;
  suffix: string | null;
  prefixCC: string | null;
  suffixCC: string | null;
  body: string;
  sealId: string | null;
  sincerelyText: string;
  recordTemplateId: string | null;
  headerId: string | null;
  footerId: string | null;
  referenceNumber?: string;
  recordId: string;
  footer: any | null;
  header: any | null;
  skipOneLevel?: boolean | null;
  receiverEmployees: ReceiverEmployeeDto[];
  receiverPositions: ReceiverPositionDto[];
  ccs: CCsDto[];
  ccList?: RecordPayloadReceiverGroup[];
  receiverList?: RecordPayloadReceiverGroup[];
  recordAttachments: RecordAttachmentDto[];
  createdAt: string;
  updatedAt: string;
  recordTagRecords: RecordTag[];
}

export interface RecordTag {
  createdAt: string;
  updatedAt: string;
  id: string;
  recordContentId: string;
  recordTagId: string;
  recordTag: {
    createdAt: string;
    updatedAt: string;
    id: string;
    name: {
      am: string;
      en: string;
    };
    key: string;
    unitId: string;
  };
}

export interface InitiatorDto {
  employee: any;
  unit: any;
  position: any;
  id: string;
  isCurrent: boolean;
  status: string;
  name: Name;
  organizationId: string;
  unitId: string;
  userId: string;
  createdAt: string;
  updatedAt: string;
}

export interface ReceivingUnitDto {
  id: string;
  recordId: string;
  unitId: string;
  createdAt: string;
  updatedAt: string;
  nonSmartOfficeReceivers: string;
  unit: {
    createdAt: string;
    id: string;
    recordId: string;
    name: NameDTO;
    organizationId: string;
    updatedAt: string;
    parentUnitId: string;
  };
}
export interface repliesDto {
  createdAt: string;
  updatedAt: string;
  amharicCreatedAt: string | null;
  amharicUpdatedAt: string | null;
  id: string;
  recordId: string;
  record?: RecordDto;
  recordContentId: string;
  comment: string;
  employeePositionId: string;
  delegatorEmployeePositionId: string | null;
  positionId: string;
  isWithDelegation: boolean;
  attachment: AttachmentInfo | null;
  uploadedSuccessfully: boolean;
  employeePosition: EmployeePositionDto;
  delegatedEmployeePosition: EmployeePositionDto | null;
  position: PositionDto;
}
export interface RecordDto {
  replies: repliesDto[];
  inReplyToIncomingInstanceId: any;
  incomingInstances: any;
  incomingInstance: any;
  initiatedAs: string;
  letterName: string;
  letterNumber: string | null | undefined;
  metadata: any;
  id: string;
  fileInfo: any | null;
  referenceNumber: string | null;
  preferredLanguage: string;
  submittedDate: string | null;
  dispatchedDate: string | null;
  statusKey: string;
  initiationType: string;
  isUploadCompleted: boolean | null;
  initiatorId: string;
  userId: string | null;
  recordTypeKey: string;
  unitId: string;
  initiator: InitiatorDto;
  delegateInitiator: InitiatorDto;
  content: RecordContentDto[];
  ccList?: RecordPayloadReceiverGroup[];
  forYourReferenceList?: RecordPayloadReceiverGroup[];
  receiverList?: RecordPayloadReceiverGroup[];
  receivingUnits: ReceivingUnitDto[];
  createdAt: string;
  updatedAt: string;
  collaborators: CollaboratorDto[];
  isWithTeamSignature: boolean;
  skipOneLevel?: boolean | null;
  outgoingInstances: OutgoingInstance[];
  amharicCreatedAt: string;
  amharicSubmittedDate: string;
  amharicDispatchedDate: string;
  isSecured: boolean;
  isUrgent: boolean;
  pageNo?: number;
  status?: string;
  isFinalLookGenerated?: boolean;
}
export interface OutgoingInstance {
  id: string;
  onReview?: boolean;
  dispatchedBy: {
    id: string;
    employee: {
      id: string;
      name: {
        am: string;
        en: string;
      };
    };
  };
}
export interface IncomingRecordDto {
  id: string;
  fileInfo: any | null;
  referenceNumber: string;
  submittedDate: string;
  subject: string;
  deliveryPersonnel: string;
  letterNumber: string;
  assignePosition: any | null;
  sendingOrganization: string;
  status: string;
  createdAt: string;
}
export interface RecordPayloadCC {
  positionId?: string;
  unitId?: string;
  employeePositionId?: string;
  type: "internal" | "external";
  isForYourReference?: boolean;
  prefix?: string;
  suffix?: string;
}

export interface RecordPayloadReceiverItem {
  id?: string;
  unitId?: string;
  positionId?: string;
  name?: string | { am: string; en: string };
  type: "unit" | "non_smart";
}

export interface RecordPayloadReceiverGroup {
  prefix: string;
  suffix: string;
  receivers: RecordPayloadReceiverItem[];
}

export interface AttachmentInfo {
  fileInfo: {
    bucket: string;
    fileName: string;
    contentType: string;
    size: number;
    originalname: string;
  };
  name: {
    am: string;
    en: string;
  };
}

export interface RecordPayload {
  referenceNumber?: string;
  useNewInternalMemoFormat?: boolean;
  recordType: string;
  initiationType: string;
  subject: string;
  preferredLanguage: "en" | "am";
  body: string;
  cc: RecordPayloadCC[];
  receivingUnitIds: string[];
  nonSmartOfficeReceivers: string[];
  nonSmartOfficeReceiverCCs: string[];
  toPositions: string[];
  toEmployees: string[];
  collaborators: string[];
  headerId?: string | null;
  footerId?: string | null;
  sincerelyText: string;
  isWithTeamSignature: boolean;
  skipOneLevel?: boolean | null;
  recordTemplateId?: string;
  letterName?: string;
  recordTagIds?: string[];
  initiatedAs?: string;
  inReplyToIncomingInstanceId?: string;
  recordPrefixId?: string;
  prefix?: string;
  suffix?: string;
  prefixCC?: string;
  suffixCC?: string;
  attachments?: AttachmentInfo[];
  receiverList?: RecordPayloadReceiverGroup[];
  ccList?: RecordPayloadReceiverGroup[];
  forYourReferenceList?: RecordPayloadReceiverGroup[];
}

export interface SendBackDto {
  instanceId: string;
  action: "approve";
  comment: string;
}

export interface AdjustmentDto {
  instanceId: string;
  action: "approve";
  comment: string;
  goBackTo?: string;
}

export interface CollaboratorDto {
  amharicSignedAt: any;
  id: string;
  createdAt: string;
  updatedAt: string;
  isCurrent: boolean;
  signStatus: "draft" | "signed" | "rejected"; // extend if needed
  signedAt: string | null;
  recordId: string;
  comment: string | null;
  employeePositionId: string;
  userId: string;
  employeePosition: CollaboratorEmployeePositionDto;
}

export interface CollaboratorEmployeePositionDto {
  id: string;
  createdAt: string;
  updatedAt: string;
  isDelegate: boolean;
  isCurrent: boolean;
  startDate: string | null;
  endDate: string | null;
  unitId: string | null;
  employeeId: string;
  positionId: string;
  employee: CollaboratorEmployeeDto;
  position: CollaboratorPositionDto;
}

export interface CollaboratorEmployeeDto {
  id: string;
  createdAt: string;
  updatedAt: string;
  isCurrent: boolean;
  status: "active" | "inactive" | "pending"; // update as needed
  name: {
    am: string;
    en: string;
  };
  organizationId: string;
  unitId: string;
  userId: string;
}

export interface CollaboratorPositionDto {
  id: string;
  createdAt: string;
  updatedAt: string;
  name: {
    am: string;
    en: string;
  };
  key: string;
  parentPositionId: string;
  unitId: string;
  organizationId: string;
  projectId: string | null;
  positionTypeId: string;
}
