import { Mark } from './mark'
import { Keys } from '../store/auth/types'
import { Event } from 'nostr-tools'

export enum UserRole {
  signer = 'Signer',
  viewer = 'Viewer'
}

export interface User {
  pubkey: string
  role: UserRole
}

export interface Meta {
  modifiedAt: number
  createSignature: string
  docSignatures: { [key: `npub1${string}`]: string }
  exportSignature?: string
  keys?: { sender: string; keys: { [user: `npub1${string}`]: string } }
  timestamps?: OpenTimestamp[]
}

export interface CreateSignatureEventContent {
  signers: `npub1${string}`[]
  viewers: `npub1${string}`[]
  fileHashes: { [key: string]: string }
  markConfig: Mark[]
  title: string
  zipUrl: string
}

export interface SignedEventContent {
  prevSig: string
  marks: Mark[]
}

export interface Sigit {
  fileUrl: string
  meta: Meta
}

export interface OpenTimestamp {
  nostrId: string
  value: string
  verification?: OpenTimestampVerification
  signature?: string
}

export interface OpenTimestampVerification {
  height: number
  timestamp: number
}

export interface OpenTimestampUpgradeVerifyResponse {
  timestamp: OpenTimestamp
  upgraded: boolean
  verified?: boolean
  verification?: OpenTimestampVerification
}

export interface UserAppData {
  /**
   * Key will be id of create signature
   */
  sigits: { [key: string]: Meta }
  /**
   * An array of ids of processed gift wrapped events
   */
  processedGiftWraps: string[]
  /**
   * Generated ephemeral key pair (https://docs.sigit.io/#/technical?id=storing-app-data).
   * This {@link Keys key pair} is used for blossom requests authentication.
   * @see {@link Keys}
   */
  keyPair?: Keys
  /**
   * Array for storing Urls for the files that stores all the sigits and processedGiftWraps on blossom.
   */
  blossomUrls: string[]
}

export interface DocSignatureEvent extends Event {
  parsedContent?: SignedEventContent
}
