export type MarketMetalType = "gold" | "silver";
export type MarketPriceStatus = "success" | "failed" | "stale" | "rate_limited" | "no_data";
export type MarketPricePlanType = "limited" | "unlimited";

export interface MarketPriceRead {
  id?: string | null;
  metal_type: MarketMetalType;
  currency_code: string;
  unit: "ounce" | "gram";
  bid_price?: string | number | null;
  ask_price?: string | number | null;
  mid_price?: string | number | null;
  price_gram?: string | number | null;
  price_gram_925?: string | number | null;
  price_gram_900?: string | number | null;
  market_time?: string | null;
  source_code: string;
  status: MarketPriceStatus;
  error_code?: string | null;
  is_stale: boolean;
  age_seconds?: number | null;
  last_successful_update_at?: string | null;
}

export interface MarketPriceLiveModeRead {
  enabled: boolean;
  allowed: boolean;
  interval_seconds: number;
  expires_at?: string | null;
  enabled_by?: string | null;
  plan_type: MarketPricePlanType;
}

export interface MarketPriceSettingsRead {
  provider: string;
  monthly_request_limit: number;
  used_requests_current_period: number;
  rate_limited_requests_current_period: number;
  request_period_start?: string | null;
  request_period_end?: string | null;
  min_manual_refresh_interval_seconds: number;
  scheduled_refresh_interval_seconds: number;
  stale_after_seconds: number;
  live_mode_enabled: boolean;
  live_mode_interval_seconds: number;
  live_mode_expires_at?: string | null;
  live_mode_enabled_by?: string | null;
  live_mode_allowed: boolean;
  live_mode_safety_reserve_requests: number;
  plan_type: MarketPricePlanType;
}

export interface MarketPriceLatestResponse {
  prices: MarketPriceRead[];
  last_successful_update_at?: string | null;
  provider: string;
  status: string;
  request_limit: number;
  used_requests: number;
  remaining_requests: number;
  next_allowed_manual_refresh_at?: string | null;
  next_scheduled_refresh_at?: string | null;
  live_mode: MarketPriceLiveModeRead;
  settings: MarketPriceSettingsRead;
}

export interface MarketPriceActionResponse {
  success: boolean;
  error_code?: string | null;
  message: string;
  detail?: string | null;
  metadata: Record<string, unknown>;
  data?: MarketPriceLatestResponse | null;
}

export interface MarketPriceLiveModeStartPayload {
  interval_seconds: number;
  duration_minutes: number;
}
