import { BaseResponse } from "@/app/[name]/(Main)/types/Types";
import { PaymentMethodEnum } from "../enum/Enum";

export interface ShipmentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  name: string;
  title: string;
  description: string;
  isActive: boolean;
}

export interface RestaurantShipmentMethod {
  id: string;
  restaurant: string;
  shipmentMethod: ShipmentMethod;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  price: number;
  minOrderPrice: number;
  isActive: boolean;
}

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

export type ShipmentMethodsResponse = BaseResponse<DeliveryMethod[]>;

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

export interface Restaurant {
  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;
  isActive: boolean;
  establishedYear: number | null;
  phoneNumber: string | 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;
}

export interface PaymentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  name: string;
  keyName: string;
  description: string;
  icon: string | null;
  isActive: boolean;
  isOnline: boolean;
  order: number;
  paymentUrl: string | null;
}

export interface RestaurantPaymentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: Restaurant;
  paymentMethod: PaymentMethod;
  merchantId: string | null;
  callbackUrl: string | null;
  isActive: boolean;
}

export interface PaymentMethodResponse {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: Restaurant;
  method: PaymentMethodEnum;
  gateway: string | null;
  description: string;
  cardNumber: string | null;
  cardOwner: string | null;
  enabled: boolean;
  order: number;
  merchantId: string | null;
  cards?: PaymentMethodCard[];
}

export type PaymentMethodsResponse = BaseResponse<PaymentMethodResponse[]>;

export interface PaymentMethodCard {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  paymentMethod: string;
  cardNumber: string;
  owner: string;
}

export type CheckoutStoreType = {
  isSelectedAddress: boolean;
  setIsSelectedAddress: (value: boolean) => void;
  selectedAddressId: string | null;
  setSelectedAddressId: (value: string | null) => void;
  isSelectedPayment: boolean;
  setIsSelectedPayment: (value: boolean) => void;
  isSelectedShipment: boolean;
  setIsSelectedShipment: (value: boolean) => void;
  deliveryType: string;
  setDeliveryType: (value: string) => void;
  paymentType: string;
  setPaymentType: (value: string) => void;
  tableNumber: number;
  setTableNumber: (value: number) => void;
  carAddress: {
    carModel: string;
    carColor: string;
    plateNumber: string;
  } | null;
  setCarAddress: (
    value: {
      carModel: string;
      carColor: string;
      plateNumber: string;
    } | null
  ) => void;
  paymentDesc: string;
  setPaymentDesc: (value: string) => void;
  paymentAttachments: string[];
  setPaymentAttachments: (value: string[]) => void;
  lastUpdated: number | null;
  setLastUpdated: (value: number | null) => void;
  clear: () => void;
};

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

export interface OrderDeliveryMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  title: string;
  method: "dineIn" | "pickup" | "deliveryCar" | "deliveryCourier";
  restaurant: Restaurant;
  deliveryFee: number;
  minOrderPrice: number;
  description: string;
  enabled: boolean;
  order: number;
}

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

export interface OrderFood {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: Restaurant;
  category: string;
  title: string;
  desc: string | null;
  content: string | null;
  price: number;
  points: number | null;
  order: number | null;
  prepareTime: number | null;
  sat: boolean;
  sun: boolean;
  mon: boolean;
  breakfast: boolean;
  noon: boolean;
  dinner: boolean;
  stock: number;
  stockDefault: number;
  isActive: boolean;
  images: string | null;
  inPlaceServe: boolean;
  pickupServe: boolean;
  rate: number;
  discount: number;
}

export interface OrderItem {
  id: string;
  createdAt: string;
  updatedAt: string;
  order: Order;
  food: OrderFood;
  quantity: number;
  unitPrice: number;
  discount: number;
  totalPrice: number;
}

export interface Order {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  user: OrderUser;
  restaurant: Restaurant;
  deliveryMethod: OrderDeliveryMethod;
  address: OrderAddress;
  paymentMethod: PaymentMethodResponse;
  orderNumber: number;
  couponDiscount: number;
  itemsDiscount: number;
  totalDiscount: number;
  subTotal: number;
  tax: number;
  shipmentFee: number;
  total: number;
  totalItems: number;
  status: string;
  paymentStatus: string;
  items?: OrderItem[];
}

export interface CreateOrderData {
  order: Order;
  paymentUrl: string;
}

export type CreateOrderResponse = BaseResponse<CreateOrderData>;

export interface OrderDetailUser {
  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 RestaurantScore {
  scoreAmount: string;
  scoreCredit: string;
  birthdayScore: string;
  purchaseScore: string;
  referrerScore: string;
  registerScore: string;
  purchaseAmount: string;
  marriageDateScore: string;
}

export interface OrderDetailRestaurant {
  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;
  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: RestaurantScore;
  plan: string;
  subscriptionId: string;
}

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

export interface OrderDetailPaymentMethod {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: string;
  method: PaymentMethodEnum;
  gateway: string | null;
  description: string;
  cardNumber: string | null;
  cardOwner: string | null;
  enabled: boolean;
  order: number;
  merchantId: string | null;
}

export interface OrderDetailFood {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  restaurant: string;
  category: string;
  title: string;
  desc: string;
  content: string[];
  price: number;
  order: number | null;
  prepareTime: number | null;
  weekDays: number[];
  mealTypes: string[];
  isActive: boolean;
  images: string[];
  inPlaceServe: boolean;
  pickupServe: boolean;
  score: number;
  discount: number;
  isSpecialOffer: boolean;
}

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

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

export interface OrderDetailPayment {
  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: unknown | null;
  paidAt: string | null;
  failedAt: string | null;
  description: string | null;
  attachments: string[];
}

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

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

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

export interface OrderDetail {
  id: string;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  user: OrderDetailUser;
  restaurant: OrderDetailRestaurant;
  deliveryMethod: OrderDetailDeliveryMethod;
  courier?: OrderDetailCourier | null;
  userAddress: OrderDetailUserAddress | null;
  carAddress: OrderDetailCarAddress | null;
  paymentMethod: OrderDetailPaymentMethod;
  orderNumber: number;
  couponDiscount: number;
  couponDetail: string | null;
  itemsDiscount: number;
  totalDiscount: number;
  subTotal: number;
  tax: number;
  deliveryFee: number;
  prepareTime: number | null;
  total: number;
  totalItems: number;
  description: string;
  tableNumber: string | null;
  status:
    | "pendingPayment"
    | "new"
    | "paid"
    | "confirmed"
    | "preparing"
    | "ready"
    | "delivering"
    | "completed"
    | "delivered"
    | "cancelled";
  history: OrderDetailHistory[];
  payments: OrderDetailPayment[];
  items: OrderDetailItem[];
}

export type OrderDetailResponse = BaseResponse<OrderDetail>;
