import type { IResponse } from "@/types/response.types";
import type { RowDataType } from "@/components/types/TableTypes";

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

export interface ServiceArea {
  type: string;
  coordinates: number[][][];
}

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

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

export interface OrderDeliveryMethod {
  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 UserAddress {
  city: string;
  phone: string;
  address: string;
  fullName: string;
  latitude: number;
  province: string;
  longitude: number;
  postalCode: string;
}

export interface CarAddress {
  phone: string;
  carColor: string;
  carModel: string;
  plateNumber: string;
}

export interface OrderPaymentMethod {
  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 OrderVariant {
  id: string;
  createdAt?: string;
  updatedAt?: string;
  deletedAt?: string | null;
  product: string;
  value: string;
  price: number;
}

export interface OrderItem {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  order: string;
  variant: OrderVariant;
  quantity: number;
  unitPrice: number;
  discount: number;
  totalPrice: number;
}

export interface OrderHistory {
  status: string;
  changedAt: string;
  desc?: string | null;
}

export interface PaymentVerifyResponseData {
  fee?: number;
  code?: number;
  wages?: unknown;
  ref_id?: number;
  message?: string;
  card_pan?: string;
  fee_type?: string;
  order_id?: string;
  card_hash?: string;
  shaparak_fee?: number;
}

export interface OrderPaymentVerifyResponse {
  data?: PaymentVerifyResponseData;
  errors?: unknown[];
}

export interface OrderPayment {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  order: string;
  amount: number;
  referenceId: string | null;
  method: string;
  gateway: string | null;
  transactionId: string | null;
  status: string;
  cardPan: string | null;
  verifyResponse: OrderPaymentVerifyResponse | null;
  paidAt: string | null;
  failedAt: string | null;
  description: string | null;
}

export interface CouponDetail {
  type: string;
  value: number;
  couponId: string;
  couponCode: string;
  couponName: string;
  maxDiscount: number;
}

export interface Order extends RowDataType {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  user: OrderUser;
  shop: OrderShop;
  deliveryMethod: OrderDeliveryMethod;
  userAddress: UserAddress | null;
  carAddress: CarAddress | null;
  paymentMethod: OrderPaymentMethod;
  paymentId?: string;
  orderNumber: number;
  couponDiscount: number;
  couponDetail: CouponDetail | null;
  itemsDiscount: number;
  totalDiscount: number;
  subTotal: number;
  tax: number;
  deliveryFee: number;
  total: number;
  totalItems: number;
  description: string;
  tableNumber?: string | null;
  status: string;
  paymentStatus?: string;
  history: OrderHistory[];
  payments: OrderPayment[];
  items: OrderItem[];
}

export type GetOrdersResponse = IResponse<Order[]>;
export type GetOrderByIdResponse = IResponse<Order>;
