import { BaseResponse } from "@/app/[name]/(Main)/types/Types";
import { ServiceArea } from "@/app/[name]/(Dialogs)/order/checkout/types/Types";

export interface HistoryOrderUser {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  firstName: string;
  lastName: string | null;
  phone: string;
  birthDate: string | null;
  marriageDate: string | null;
  referrer: string | null;
  isActive: boolean;
  gender: boolean;
  avatarUrl: string | null;
}

export interface HistoryOrderRestaurantScore {
  scoreAmount: string;
  scoreCredit: string;
  birthdayScore: string;
  purchaseScore: string;
  referrerScore: string;
  registerScore: string;
  purchaseAmount: string;
  marriageDateScore: string;
}

export interface HistoryOrderRestaurant {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  name: string;
  slug: string;
  logo: string | null;
  address: string | null;
  menuColor: string | null;
  latitude: number | null;
  longitude: number | null;
  serviceArea: ServiceArea | null;
  isActive: boolean;
  establishedYear: number | null;
  phone: string;
  instagram: string | null;
  telegram: string | null;
  whatsapp: string | null;
  description: string | null;
  seoTitle: string | null;
  seoDescription: string | null;
  tagNames: string | null;
  images: string | null;
  vat: number;
  domain: string;
  score: HistoryOrderRestaurantScore;
  plan: string;
  subscriptionId: string;
  subscriptionEndDate: string;
  subscriptionStartDate: string;
}

export interface HistoryOrderDeliveryMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  method: "dineIn" | "pickup" | "deliveryCar" | "deliveryCourier";
  restaurant: string;
  deliveryFee: number;
  deliveryFeeType: string;
  perKilometerFee: number | null;
  distanceBasedMinCost: number | null;
  minOrderPrice: number;
  description: string;
  enabled: boolean;
  order: number;
}

export interface HistoryOrderCourier {
  id: string;
  fullName: string;
  phone: string;
}

export interface HistoryOrderUserAddress {
  phone: string;
  address: string;
  fullName: string;
  latitude: number;
  longitude: number;
  postalCode: string;
}

export interface HistoryOrderAddress {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  user: string;
  title: string;
  address: string;
  postalCode: string;
  latitude: number;
  longitude: number;
  phone: string;
  isDefault: boolean;
}

export interface HistoryOrderPaymentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: string;
  method: "CardOnDelivery" | "Cash" | "Online" | "Wallet";
  gateway: string | null;
  description: string;
  enabled: boolean;
  order: number;
  merchantId: string | null;
}

export interface HistoryOrderFood {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: string;
  category: string;
  title: string;
  desc: string | null;
  content: string | null;
  price: number;
  order: number | null;
  prepareTime: number | null;
  weekDays: number[];
  mealTypes: ("breakfast" | "lunch" | "dinner" | "snack")[];
  isActive: boolean;
  images: string[] | null;
  inPlaceServe: boolean;
  pickupServe: boolean;
  score: number;
  discount: number;
  isSpecialOffer: boolean;
}

export interface HistoryOrderItem {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  order: string;
  food: HistoryOrderFood;
  quantity: number;
  unitPrice: number;
  discount: number;
  totalPrice: number;
}

export interface HistoryOrderHistoryItem {
  status: string;
  changedAt: string;
}

export interface HistoryOrder {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  user: HistoryOrderUser;
  restaurant: HistoryOrderRestaurant;
  deliveryMethod: HistoryOrderDeliveryMethod;
  courier?: HistoryOrderCourier | null;
  userAddress: HistoryOrderUserAddress | null;
  carAddress: HistoryOrderUserAddress | null;
  paymentMethod: HistoryOrderPaymentMethod;
  orderNumber: number;
  couponDiscount: number;
  couponDetail: unknown | null;
  itemsDiscount: number;
  totalDiscount: number;
  subTotal: number;
  tax: number;
  deliveryFee: number;
  total: number;
  totalItems: number;
  description: string;
  tableNumber: string | null;
  status: string;
  history: HistoryOrderHistoryItem[];
  items: HistoryOrderItem[];
}

export interface OrdersResponseMeta {
  total: number;
  page: number;
  limit: number;
  totalPages: number;
}

export interface OrdersResponseData {
  data: HistoryOrder[];
  meta: OrdersResponseMeta;
}

export type OrdersResponse = BaseResponse<HistoryOrder[]> & {
  meta?: OrdersResponseMeta;
};

