import {test} from "@playwright/test"
import { v4 as uuidv4 } from "uuid";

import {ProductsPage} from "../page-objects/ProductsPage.js"
import { Navigation } from "../page-objects/Navigation.js"
import { CheckoutPage } from "../page-objects/CheckoutPage.js"
import { LoginPage } from "../page-objects/LoginPage.js"
import { RegisterPage } from "../page-objects/RegisterPage.js"
import { DeliveryPage } from "../page-objects/DeliveryPage.js"
import { deliveryDetails } from "../data/deliveryDetails.js";
import { PaymentPage } from "../page-objects/PaymentPage.js"
import { paymentDetails } from "../data/paymentDetails.js";


test.only("New user full end-to-end test journey", async ({page}) => {
    
    // init
    const productsPage = new ProductsPage(page)
    const navigation = new Navigation(page)
    const checkoutPage = new CheckoutPage(page)
    const loginPage = new LoginPage(page)
    const registerPage = new RegisterPage(page)
    const deliveryPage = new DeliveryPage(page)
    const paymentPage = new PaymentPage(page)

    // 1. Visit
    await productsPage.visit()
    await productsPage.sortByCheapest()
    // 2. Add to Basket
    await productsPage.addProductToBasket(0)
    await productsPage.addProductToBasket(1)
    await productsPage.addProductToBasket(2)
    // 3. Navigate to Checkout
    await navigation.goToCheckout()

    await checkoutPage.removeCheapestProduct()
    await checkoutPage.continueToCheckout()
    // 4. Navigate to Signup
    await loginPage.moveToSignup()

    const email = uuidv4() + "@gmail.com"
    const password = "secret"
    // 5. Register New User
    await registerPage.signupNewUser(email, password)

    await deliveryPage.fillDeliveryDetails(deliveryDetails[0])
    await deliveryPage.saveAddress()
    // await deliveryPage.clearDetails()
    // await deliveryPage.fillDetails(deliveryDetails[1])
    // await deliveryPage.saveAddress()
    // await deliveryPage.clearDetails()
    // await deliveryPage.fillDetails(deliveryDetails[2])
    // await deliveryPage.saveAddress()

    await deliveryPage.continueToPayment()

    await paymentPage.activateDiscount()
    await paymentPage.fillPaymentDetails(paymentDetails)
    await paymentPage.completePayment()


    // Hold
    //await page.pause();
})