/**
 * @alqove/types
 *
 * TypeScript types generated from the OpenAPI spec.
 * DO NOT EDIT MANUALLY — run `npm run generate` to regenerate.
 *
 * Manual type additions go in this file (index.ts).
 * Generated types live in generated.ts.
 */

// Re-export generated types
export type * from './generated';

/** Standard API response wrapper */
export interface ApiResponse<T> {
  data: T;
  message?: string;
  /**
   * Soft warning for "local action persisted but external system failed"
   * — most commonly Stripe call failure on a cancellation/refund/reversal.
   * Status code stays 200 because the local state is recorded; UI should
   * surface this as a non-blocking banner so the user knows reconciliation
   * is needed.
   */
  warning?: {
    stripe_error?: string;
  };
}

/** Paginated API response */
export interface PaginatedResponse<T> {
  data: T[];
  meta: {
    current_page: number;
    last_page: number;
    per_page: number;
    total: number;
  };
  links: {
    first: string;
    last: string;
    prev: string | null;
    next: string | null;
  };
}

/** API error response */
export interface ApiError {
  message: string;
  errors?: Record<string, string[]>;
  status: number;
}

/** Money values are always integers (cents) */
export type Cents = number;

/** Auth request/response types */
export interface RegisterPayload {
  name: string;
  email: string;
  password: string;
  password_confirmation: string;
}

export interface LoginPayload {
  email: string;
  password: string;
}

export interface AuthUser {
  id: string;
  email: string;
  name: string;
  avatar: string | null;
  roles: string[];
  /**
   * Owned store id — **deprecated**, kept during the Port 00 transition.
   * Read store access from the auth store's `memberships`
   * (GET /v1/me/memberships) instead; each carries resolved capabilities.
   */
  store_id: string | null;
  created_at: string;
}

export interface AuthData {
  token: string;
  user: AuthUser;
}

export interface UpdateProfilePayload {
  name?: string;
  email?: string;
  avatar?: string | null;
}

/** Store types */
export interface StoreData {
  id: string;
  name: string;
  description: string | null;
  logo_image: string | null;
  city: string;
  state: string;
  is_verified: boolean;
  stripe_connected: boolean;
  created_at: string;
}

export interface StoreSettingsData {
  flat_shipping_rate: Cents;
  free_shipping_threshold: Cents | null;
  minimum_order_amount: Cents | null;
  processing_days: number;
  return_window_days: number;
  return_policy_text: string | null;
}

export interface CreateStorePayload {
  owner_user_id: string;
  name: string;
  description?: string | null;
  logo_image?: string | null;
  city: string;
  state: string;
  flat_shipping_rate: Cents;
  free_shipping_threshold?: Cents | null;
  minimum_order_amount?: Cents | null;
  processing_days?: number;
  return_window_days?: number;
  return_policy_text?: string | null;
}

export interface UpdateStorePayload {
  name?: string;
  description?: string | null;
  logo_image?: string | null;
  city?: string;
  state?: string;
}

export interface UpdateStoreSettingsPayload {
  flat_shipping_rate?: Cents;
  free_shipping_threshold?: Cents | null;
  minimum_order_amount?: Cents | null;
  processing_days?: number;
  return_window_days?: number;
  return_policy_text?: string | null;
}

/** Item types */
export interface ItemImage {
  id: number;
  url: string;
  thumb: string;
  medium: string;
  large: string;
  og: string;
  order: number;
}

export interface ItemSummaryData {
  id: string;
  title: string;
  price: Cents;
  condition: string;
  brand: string | null;
  size: string | null;
  status: string;
  image_url: string | null;
  store: {
    id: string;
    name: string;
    city: string;
    state: string;
  };
  created_at: string;
  /** Denormalized store-level average rating (1..5). Null until the store has any reviews. */
  store_average_rating?: number | null;
  /** Denormalized count of visible reviews on the store. */
  store_review_count?: number | null;
  /** Store-level dimension average — item-as-described (1..5). */
  rating_item_as_described?: number | null;
  /** Store-level dimension average — shipping speed (1..5). */
  rating_shipping_speed?: number | null;
  /** Store-level dimension average — communication (1..5). */
  rating_communication?: number | null;
  /** Store-level dimension average — packaging (1..5). */
  rating_packaging?: number | null;
}

export interface ItemCategoryPathSegment {
  id: number;
  name: string;
  slug: string;
}

export interface ItemStoreRatingBreakdown {
  item_as_described: number | null;
  shipping_speed: number | null;
  communication: number | null;
  packaging: number | null;
}

export interface ItemStorePoliciesData {
  flat_shipping_rate: Cents | null;
  free_shipping_threshold: Cents | null;
  minimum_order_amount: Cents | null;
  processing_days: number | null;
  return_window_days: number | null;
  return_policy_text: string | null;
}

export interface ItemDetailData {
  id: string;
  title: string;
  description: string;
  price: Cents;
  original_retail: Cents | null;
  condition: string;
  brand: string | null;
  size: string | null;
  colors: string[] | null;
  measurements: Record<string, string> | null;
  status: string;
  category: {
    id: number;
    name: string;
    slug: string;
  };
  category_path?: ItemCategoryPathSegment[];
  store: {
    id: string;
    name: string;
    city: string;
    state: string;
    is_verified?: boolean;
    is_suspended?: boolean;
    average_rating?: number | null;
    review_count?: number | null;
    rating_breakdown?: ItemStoreRatingBreakdown;
    policies?: ItemStorePoliciesData;
  };
  images: ItemImage[];
  view_count: number;
  save_count: number;
  sold_at: string | null;
  created_at: string;
  updated_at: string;
  /** Denormalized store-level average rating (1..5). Null until the store has any reviews. */
  store_average_rating?: number | null;
  /** Denormalized count of visible reviews on the store. */
  store_review_count?: number | null;
  /** Store-level dimension average — item-as-described (1..5). */
  rating_item_as_described?: number | null;
  /** Store-level dimension average — shipping speed (1..5). */
  rating_shipping_speed?: number | null;
  /** Store-level dimension average — communication (1..5). */
  rating_communication?: number | null;
  /** Store-level dimension average — packaging (1..5). */
  rating_packaging?: number | null;
}

export interface CreateItemPayload {
  title: string;
  // Draft-create accepts a minimal payload (title + category_id + condition).
  // Description/price are optional at draft time; publish enforces them.
  description?: string | null;
  category_id: number;
  brand?: string | null;
  size?: string | null;
  condition: string;
  colors?: string[] | null;
  measurements?: Record<string, string> | null;
  price?: Cents | null;
  original_retail?: Cents | null;
}

export interface UpdateItemPayload {
  title?: string;
  description?: string | null;
  category_id?: number;
  brand?: string | null;
  size?: string | null;
  condition?: string;
  colors?: string[] | null;
  measurements?: Record<string, string> | null;
  price?: Cents | null;
  original_retail?: Cents | null;
}
