import { AddressListInOrderDetails,OrderAddressType } from "@/types/customer/type";
import { CartAddress } from "@/types/cart/type";

export function getAddressFromOrderDetailAddressList(addressList: AddressListInOrderDetails, addressType: OrderAddressType) {
    const address = addressList.edges.find((x) => x.node.addressType === addressType);

    if (!address) {
        throw new Error(
            "Order shipping address missing"
        );
    }
    const res:  CartAddress = {
        id: String(address.node._id),
        firstName: address.node.firstName,
        lastName: address.node.lastName,
        email: address.node.email,
        address: address.node.address,
        city: address.node.city,
        state: address.node.state,
        country: address.node.country,
        postcode: address.node.postcode,
        phone: address.node.phone,
     }

    return res;

}