/**
 * Contract signing page types — wave-11 leaf-C (contract-signing-page).
 * Matches the wire contract of `GET /api/sign/:token` (owned by contracts-esignature).
 * Used by: apps/zync-www signing island and apps/zync-api sign routes.
 */

export type SignContractStatus = 'DRAFT' | 'SENT' | 'VIEWED' | 'SIGNED' | 'VOIDED'

export interface SignTenantBranding {
  logoR2Key: string | null
  primaryColor: string | null
  tenantName: string
  customDomain: boolean      // true when tenant has an active custom domain
  locale: 'he' | 'en' | null
}

export interface SignPageData {
  contract: {
    title: string
    content: unknown           // Tiptap JSONB document
    signingDeadline: string    // ISO; from contract_signatories.token_expires_at
    status: SignContractStatus
    signedPdfReady: boolean
  }
  signatory: {
    name: string
    email: string
    order: number
    signedAt: string | null
    declinedAt: string | null
    declinedReason: string | null
  }
  waitingFor?: { name: string }  // prior unsigned signatory in signing order
  tenantBranding: SignTenantBranding
}

export interface SignSubmitBody {
  signature_data: string          // data:image/png;base64,...
  signature_type: 'drawn' | 'typed'
  name: string
  email: string
}

export interface SignDeclineBody {
  reason?: string
}
