"use client";

import type {
  CommercialTerms,
  EstimateDemandLineMetadata,
  EstimateExportArtifactPayload,
  EstimateExportFormat,
  EstimateStatus,
  EstimateVersionStatus,
} from "@capakraken/shared";

export interface EstimateMetricView {
  id: string;
  key: string;
  label: string;
  valueDecimal: number;
  valueCents?: number | null;
  currency?: string | null;
}

export interface EstimateAssumptionView {
  id: string;
  category: string;
  key: string;
  label: string;
  valueType: string;
  value: unknown;
  notes?: string | null;
}

export interface EstimateScopeItemView {
  id: string;
  sequenceNo: number;
  scopeType: string;
  packageCode?: string | null;
  name: string;
  description?: string | null;
  frameCount?: number | null;
  itemCount?: number | null;
  unitMode?: string | null;
}

export interface EstimateDemandLineView {
  id: string;
  scopeItemId?: string | null;
  roleId?: string | null;
  resourceId?: string | null;
  lineType: string;
  name: string;
  chapter?: string | null;
  rateSource?: string | null;
  hours: number;
  currency: string;
  costRateCents: number;
  billRateCents: number;
  costTotalCents: number;
  priceTotalCents: number;
  monthlySpread?: Record<string, number>;
  metadata: EstimateDemandLineMetadata;
}

export interface EstimateResourceSnapshotView {
  id: string;
  resourceId?: string | null;
  sourceEid?: string | null;
  displayName: string;
  chapter?: string | null;
  roleId?: string | null;
  currency: string;
  lcrCents: number;
  ucrCents: number;
  fte?: number | null;
  location?: string | null;
  country?: string | null;
  level?: string | null;
  workType?: string | null;
  attributes: Record<string, unknown>;
}

export interface EstimateExportView {
  id: string;
  fileName: string;
  format: EstimateExportFormat;
  payload?: EstimateExportArtifactPayload | Record<string, unknown> | null;
  createdAt: Date;
}

export interface EstimateVersionView {
  id: string;
  versionNumber: number;
  label?: string | null;
  status: EstimateVersionStatus;
  notes?: string | null;
  lockedAt?: Date | null;
  updatedAt: Date;
  assumptions: EstimateAssumptionView[];
  scopeItems: EstimateScopeItemView[];
  demandLines: EstimateDemandLineView[];
  resourceSnapshots: EstimateResourceSnapshotView[];
  metrics: EstimateMetricView[];
  exports: EstimateExportView[];
  commercialTerms?: CommercialTerms | null;
}

export interface EstimateWorkspaceView {
  id: string;
  name: string;
  status: EstimateStatus;
  projectId?: string | null;
  opportunityId?: string | null;
  baseCurrency: string;
  updatedAt: Date;
  project?: {
    id: string;
    name: string;
    shortCode: string;
    startDate?: string | Date | null;
    endDate?: string | Date | null;
  } | null;
  versions: EstimateVersionView[];
}

export type WorkspaceTab =
  | "overview"
  | "assumptions"
  | "scope"
  | "staffing"
  | "financials"
  | "phasing"
  | "versions"
  | "exports"
  | "comments";
