export type Locale = "ar" | "en";

export type PaginationMeta = {
  current_page: number;
  last_page: number;
  per_page: number;
  total: number;
};

export type Banner = {
  id: number;
  title_ar?: string | null;
  title_en?: string | null;
  image: string;
  placement?: "home_hero" | "general";
  type: "store" | "coupon" | "cashback" | "external";
  reference_id?: number | null;
  external_url?: string | null;
};

export type Category = {
  id: number;
  name_ar: string;
  name_en: string;
  slug: string;
  icon?: string | null;
  image?: string | null;
  coupons_count?: number;
  stores_count?: number;
  sort_order?: number;
  status?: boolean;
};

export type Store = {
  id: number;
  category_id?: number;
  category?: Category;
  name_ar: string;
  name_en: string;
  slug: string;
  logo?: string | null;
  cover_image?: string | null;
  description_ar?: string | null;
  description_en?: string | null;
  intro_ar?: string | null;
  intro_en?: string | null;
  faq_question_ar?: string | null;
  faq_answer_ar?: string | null;
  faq_question_en?: string | null;
  faq_answer_en?: string | null;
  website_url?: string | null;
  affiliate_url?: string | null;
  cashback_enabled?: boolean;
  cashback_rate?: string | number;
  is_featured?: boolean;
  status?: boolean;
  coupons_count?: number;
  cashback_offers_count?: number;
};

export type Coupon = {
  id: number;
  store_id: number;
  store?: Store;
  title_ar: string;
  title_en: string;
  description_ar?: string | null;
  description_en?: string | null;
  details_ar?: string | null;
  details_en?: string | null;
  code?: string | null;
  type: "code" | "deal";
  discount_type: "percentage" | "fixed" | "text";
  discount_value?: string | null;
  start_date?: string | null;
  end_date?: string | null;
  usage_count?: number;
  is_featured?: boolean;
  status?: boolean;
};

export type CashbackOffer = {
  id: number;
  store_id: number;
  store?: Store;
  title_ar: string;
  title_en: string;
  description_ar?: string | null;
  description_en?: string | null;
  rate: string | number;
  terms_ar?: string | null;
  terms_en?: string | null;
  status?: boolean;
};

export type CashbackTransaction = {
  id: number;
  store_id: number;
  cashback_offer_id?: number | null;
  store?: Pick<Store, "id" | "name_ar" | "name_en" | "slug" | "logo"> | null;
  cashback_offer?: Pick<CashbackOffer, "id" | "title_ar" | "title_en" | "rate"> | null;
  order_reference?: string | null;
  amount: string | number;
  status: "pending" | "approved" | "rejected" | "paid";
  confirmed_at?: string | null;
  paid_at?: string | null;
  notes?: string | null;
  created_at: string;
};

export type Article = {
  id: number;
  title_ar: string;
  title_en: string;
  slug: string;
  excerpt_ar?: string | null;
  excerpt_en?: string | null;
  content_ar?: string | null;
  content_en?: string | null;
  image?: string | null;
  author_name?: string | null;
  published_at?: string | null;
  is_featured?: boolean;
  sort_order?: number;
  status?: boolean;
};

export type NotificationItem = {
  id: number;
  title_ar: string;
  title_en: string;
  body_ar: string;
  body_en: string;
  type?: string | null;
  reference_id?: number | null;
  audience?: string | null;
  sent_at?: string | null;
  is_read?: boolean;
  read_at?: string | null;
};

export type PageContent = {
  id: number;
  key: string;
  title_ar: string;
  title_en: string;
  content_ar?: string | null;
  content_en?: string | null;
  status?: boolean;
};

export type User = {
  id: number;
  name: string;
  email?: string | null;
  phone?: string | null;
  avatar?: string | null;
  status?: string;
  wallet_balance?: string | number;
  referral_code?: string | null;
  referred_by?: number | null;
  country?: { id: number; name_ar: string; name_en: string; iso_code: string } | null;
  language?: { id: number; name: string; code: string } | null;
};

export type AffiliateSummary = {
  referral_code: string;
  reward_amount: number;
  referral_link?: string | null;
  android_url?: string | null;
  ios_url?: string | null;
  description_ar?: string | null;
  description_en?: string | null;
  counts: {
    total: number;
    pending: number;
    approved: number;
    paid: number;
    rejected: number;
  };
  pending_earnings: number;
  paid_earnings: number;
  recent_referrals: Array<{
    id: number;
    status: "pending" | "approved" | "rejected" | "paid";
    reward_amount: string | number;
    invited_user?: {
      id: number;
      name: string;
      email?: string | null;
      created_at?: string | null;
    } | null;
    created_at?: string | null;
  }>;
  commission_reports: Array<{
    id: number;
    type: "credit" | "debit";
    source: "affiliate_commission" | "affiliate_commission_refund" | string;
    amount: string | number;
    balance_before: string | number;
    balance_after: string | number;
    reference_type?: string | null;
    reference_id?: number | null;
    description?: string | null;
    created_at?: string | null;
  }>;
};

export type Country = {
  id: number;
  name_ar: string;
  name_en: string;
  iso_code: string;
  flag?: string | null;
};

export type Language = {
  id: number;
  name: string;
  code: string;
  direction: "rtl" | "ltr";
};

export type HomePayload = {
  banners: Banner[];
  featured_categories: Category[];
  featured_stores: Store[];
  featured_coupons: Coupon[];
  cashback_stores: Store[];
  latest_coupons: Coupon[];
  articles: Article[];
};

export type FavoriteListPayload = {
  stores?: Store[];
  coupons?: Coupon[];
  items?: FavoriteItem[];
};

export type FavoriteItem = {
  id?: number;
  favoritable_type?: string;
  favoritable_id?: number;
  favoritable?: Store | Coupon;
  store?: Store;
  coupon?: Coupon;
};

export type PublicSetting = {
  key: string;
  value: string | null;
  group?: string | null;
  type?: string | null;
};

export type LandingPage = {
  id: number;
  name_ar: string;
  name_en: string;
  slug: string;
  logo?: string | null;
  subtitle_ar?: string | null;
  subtitle_en?: string | null;
  coupon_code: string;
  purchase_url: string;
  after_copy_message_ar?: string | null;
  after_copy_message_en?: string | null;
  cta_button_text_ar?: string | null;
  cta_button_text_en?: string | null;
};

export type TrackingCode = {
  id: number;
  platform_name: string;
  slug: string;
  script_code: string;
  position: "head" | "body_end";
  sort_order?: number;
};

export type UserBankAccount = {
  id: number;
  bank_name: string;
  account_holder_name: string;
  iban?: string | null;
  account_number?: string | null;
  masked_account_number?: string | null;
  swift_code?: string | null;
  currency_code: string;
  is_default: boolean;
  is_active: boolean;
  created_at: string;
};

export type WalletWithdrawal = {
  id: number;
  user_bank_account_id?: number | null;
  requested_amount: string | number;
  status: "pending" | "processing" | "paid" | "rejected" | "cancelled";
  bank_name: string;
  account_holder_name: string;
  iban?: string | null;
  account_number?: string | null;
  masked_account_number?: string | null;
  swift_code?: string | null;
  currency_code: string;
  note?: string | null;
  processed_at?: string | null;
  created_at: string;
};

export type WalletTransaction = {
  id: number;
  type: "credit" | "debit";
  source: string;
  amount: string | number;
  balance_before: string | number;
  balance_after: string | number;
  reference_type?: string | null;
  reference_id?: number | null;
  description?: string | null;
  created_at: string;
};
