// Row shapes for the muzick schema, extracted verbatim from db.service.ts so
// that file is about behaviour and this one about data. Re-exported from
// db.service.ts, so an existing `import { Track } from '../services/db.service.js'`
// keeps working.

export interface Artist {
  id: string;
  name: string;
  mbid?: string | null;
  discogs_id?: string | null;
  image_path?: string | null;
}

export interface Album {
  id: string;
  artist_id: string;
  title: string;
  year?: number | null;
  artwork_id?: string | null;
}

export interface TrackArtist {
  id: string;
  name: string;
  role: 'main' | 'featured';
}

export interface Track {
  id: string;
  path: string;
  hash: string;
  title: string;
  artist: string;
  album_id: string;
  duration: number;
  state: string;
  play_count: number;
  skip_count: number;
  dislike_count: number;
  last_played_at?: Date | null;
  mtime?: number | null;
  source_type: string;
  artists?: TrackArtist[];
}

export const FEEDBACK_ACTIONS = ['promoted', 'disliked', 'skipped', 'deleted_permanent'] as const;
export type FeedbackAction = (typeof FEEDBACK_ACTIONS)[number];

export interface HistoryEntry extends Track {
  history_id: string;
  batch_id: string | null;
  played_at: Date;
  completed: boolean;
}

export interface Genre {
  id: string;
  name: string;
  parent_id?: string | null;
  track_count?: number;
}

export interface DislikeEntry {
  track_id: string;
  disliked_at: Date;
  warned_at: Date | null;
  deleted_at: Date | null;
  grace_hours: number;
  state: string; // 'HIDDEN' | 'WARNED' | 'DELETED'
  track_title: string;
  track_artist: string;
  track_path: string;
}

export interface ArtistWithAlbums {
  id: string;
  name: string;
  mbid?: string | null;
  discogs_id?: string | null;
  image_path?: string | null;
  albums: Album[];
}

export interface AlbumWithTracks {
  id: string;
  artist_id: string;
  title: string;
  year?: number | null;
  artwork_id?: string | null;
  tracks: Track[];
}


// ---------------------------------------------------------------------------
// v2 Recommendation Engine types
// ---------------------------------------------------------------------------

export interface Claim {
  id: string;
  user_id: string | null;
  subject_type: string;
  subject_id: string;
  predicate: string;
  object_type: string;
  object_id: string;
  source: string;
  confidence: number;
  evidence_at: Date;
  last_reinforced_at: Date;
  raw: unknown | null;
  created_at: Date;
}

export interface Evidence {
  id: string;
  user_id: string;
  entity_type: string;
  entity_id: string;
  signal: string;
  profile: string;
  weight: number;
  context: unknown | null;
  created_at: Date;
}

export interface ListenerBelief {
  user_id: string;
  profile: string;
  entity_type: string;
  entity_id: string;
  dimension: string;
  value: number;
  confidence: number;
  evidence_count: number;
  last_reinforced_at: Date;
  last_decayed_at: Date;
}

export interface ClaimEdge {
  subjectType: string;
  subjectId: string;
  predicate: string;
  objectType: string;
  objectId: string;
  fusedValue: number;
}

export interface SessionState {
  session_id: string;
  user_id: string;
  started_at: Date;
  last_interaction: Date;
  context: string | null;
  state_vector: Record<string, unknown>;
}

export interface DiversityBudget {
  user_id: string;
  dimension: string;
  budget_share: number;
  horizon_min: number;
}

export interface RepetitionRule {
  user_id: string;
  dimension: string;
  min_distance: number;
}
