import { CartDetail, CartAddress } from "@/types/cart/type";
import {ShipAddressFormData,BillAddressFormData} from "@/types/checkout/type";
export function formatCartDetail(cart:CartDetail): CartDetail { 
    return {
        id: cart.id,
        appliedTaxes: cart.appliedTaxes,
        itemsQty: cart.itemsQty,
        isGuest: cart.isGuest,
        itemsCount: cart.itemsCount,
        items: cart.items,
        subtotal: cart.subtotal,
        subTotalInclTax: cart.subTotalInclTax,
        discountAmount: cart.discountAmount,
        taxAmount: cart.taxAmount,
        taxTotal: cart.taxTotal,
        shippingAmount: cart.shippingAmount,
        shippingAmountInclTax: cart.shippingAmountInclTax,
        grandTotal: cart.grandTotal,
    
        formattedSubtotal: cart.formattedSubtotal,
        formattedSubTotalInclTax: cart.formattedSubTotalInclTax,

        formattedDiscountAmount: cart.formattedDiscountAmount,
        formattedTaxAmount: cart.formattedTaxAmount,
        formattedTaxTotal: cart.formattedTaxTotal,
        formattedShippingAmount: cart.formattedShippingAmount,
        formattedShippingAmountInclTax: cart.formattedShippingAmountInclTax,
        formattedGrandTotal: cart.formattedGrandTotal,
        couponCode: cart.couponCode,

        selectedShippingRate: cart.selectedShippingRate,
        selectedShippingRateTitle: cart.selectedShippingRateTitle,
        paymentMethod: cart.paymentMethod,
        paymentMethodTitle: cart.paymentMethodTitle,
    
        haveStockableItems: cart.haveStockableItems,
        billingAddress: cart.billingAddress,
        shippingAddress: cart.shippingAddress
    };
}

export function shippingAddressToCartAddress(address:ShipAddressFormData ): CartAddress { 
    const res: CartAddress = {
        id: String(address.shippingAddressId),
        firstName: address.shippingFirstName,
        lastName: address.shippingLastName,
        email: address.shippingEmail,
        address: address.shippingAddress,
        city: address.shippingCity,
        state: address.shippingState,
        country: address.shippingCountry,
        postcode: address.shippingPostcode,
        phone: address.shippingPhoneNumber,

    }
    return res;
   
}

export function billingAddressToCartAddress(address: BillAddressFormData):CartAddress {
    const res: CartAddress = {
        id: String(address.billingAddressId),
        firstName: address.billingFirstName,
        lastName: address.billingLastName,
        email: address.billingEmail,
        address: address.billingAddress,
        city: address.billingCity,
        state: address.billingState,
        country: address.billingCountry,
        postcode: address.billingPostcode,
        phone: address.billingPhoneNumber
    }
    return res;
}