import { BaseResponse, Product } 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;
  birthDate: string | null;
  marriageDate: string | null;
  referrer: string | null;
  isActive: boolean;
  gender: boolean;
  avatarUrl: string | null;
  phone: string;
}

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

export interface HistoryOrderShop {
  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;
  subscriptionId: string;
  subscriptionEndDate: string;
  subscriptionStartDate: string;
}

export interface HistoryOrderDeliveryMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  method: string;
  shop: string;
  deliveryFee: number;
  deliveryFeeType: string;
  perKilometerFee: number | null;
  distanceBasedMinCost: number | null;
  minOrderPrice: number;
  description: string;
  enabled: boolean;
  order: number;
}

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

export interface HistoryOrderPaymentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  shop: string;
  method: string;
  gateway: string | null;
  description: string;
  enabled: boolean;
  order: number;
  merchantId: string | null;
}

export interface HistoryOrderVariant {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  value: string;
  price: number;
  product: Product;
}

export interface HistoryOrderItem {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  order: string;
  variant: HistoryOrderVariant;
  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;
  shop: HistoryOrderShop;
  deliveryMethod: HistoryOrderDeliveryMethod;
  userAddress: 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;
  status: string;
  history: HistoryOrderHistoryItem[];
  items: HistoryOrderItem[];
}

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

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