# Type Definitions

All types live in `types.ts` at the project root.

## Core Record Types

```typescript
interface SalesRecord {
  id: string;
  customer: string;       // "Amazon DE", "Amazon UK", etc.
  year: number;
  month: string;          // "Apr-23" format
  week?: number;
  asin: string;
  sku: string;
  title: string;
  articleName: string;
  units: number;
  sellOut: number;        // € value
  line: string;           // Product line
}

interface AdsRecord {
  country: string;        // "Amazon DE", etc.
  year: number;
  week: number;
  asin: string;
  cost: number;
  clicks: number;
  impressions: number;
  cpc: number;
  ctr: number;
  acos: number;
  conversions: number;
  attributedUnits30d: number;
  attributedSales30d: number;
}

interface TrafficRecord {
  country: string;
  year: number;
  week: number;
  asin: string;
  glanceViews: number;
}

interface ForecastRecord {
  asin: string;
  annualForecast: number;
  sku?: string;
  title?: string;
  line?: string;
}
```

## Filter Types

```typescript
interface FilterState {
  customer: string[];
  year: string[];
  month: string[];
  line: string[];
  asin: string[];
  sku: string[];
  title: string[];
  week: string[];
  stock: string[];
  vendorStock: string[];
  woc: string[];              // Weeks of Coverage
  bulkSearch: string;
  columnFilters: Record<string, ColumnFilterCondition>;
}

interface ColumnFilterCondition {
  textFilter?: {
    operator: 'equals' | 'notEquals' | 'contains' | 'notContains' | 'startsWith' | 'notStartsWith' | 'endsWith' | 'notEndsWith' | 'gt' | 'lt' | 'gte' | 'lte';
    value: string;
  };
  selectedValues?: string[];
  sort?: 'asc' | 'desc';
}
```

## Aggregated Data

```typescript
interface AggregatedData {
  totalSellOut: number;
  totalUnits: number;
  totalsByYear: Record<string, { sellOut: number; units: number }>;
  byLine: { name: string; value: number; units: number }[];
  byCustomer: { name: string; value: number }[];
  seasonality: SeasonalityPoint[];
  seasonalityUnits: SeasonalityPoint[];
  availableYears: string[];
  topMovers: GrowthMetric[];
  bottomMovers: GrowthMetric[];
  comparisonPeriods: { current: string; previous: string };
  topLinesSplit: YearlySplitData[];
  byCustomerSplit: YearlySplitData[];
  byLineOverviewSplit: YearlySplitData[];
}
```

## Growth Metrics

```typescript
interface GrowthMetric {
  line: string;
  currentYearSellOut: number;
  previousYearSellOut: number;
  sellOutGrowthValue: number;
  sellOutGrowthPercentage: number;
  currentYearUnits: number;
  previousYearUnits: number;
  unitsGrowthValue: number;
  unitsGrowthPercentage: number;
}
```

## Combined KPIs (Sales + Ads merged)

```typescript
interface CombinedKPIs {
  id: string;
  marketplace: string;
  customer: string;
  month: string;
  week: number;
  year: number;
  asin: string;
  title: string;
  line: string;
  sku: string;
  salesTotal: number;
  unitsTotal: number;
  salesAds: number;
  unitsAds: number;
  cost: number;
  clicks: number;
  impressions: number;
  conversions: number;
  salesOrganic: number;
  unitsOrganic: number;
  paidSalesShare: number;
  organicSalesShare: number;
  acos: number;
  tacos: number;
  roas: number;
  ctr: number;
  cpc: number;
  cvrUnits: number;
  glanceViews: number;
  avgWeeklySales?: number;
}
```

## Pivot Table

```typescript
interface PivotRow {
  id: string;
  customer: string;
  line: string;
  title: string;
  articleName: string;
  sku: string;
  asin: string;
  totalsByYear: Record<string, YearlyData>;
  months: MonthlyPivot[];    // Always 12 elements
  adsByYear?: Record<string, {
    adSpend: number;
    attributedSales: number;
    acos: number;
    tacos: number;
  }>;
}
```
