package ru.otus.mobile.tests;

import com.google.inject.Inject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import ru.otus.mobile.annotations.MobileUser;
import ru.otus.mobile.config.TestAccount;
import ru.otus.mobile.config.TestContext;
import ru.otus.mobile.db.DbClient;
import ru.otus.mobile.extensions.MobileExtension;
import ru.otus.mobile.page.LoginPage;
import ru.otus.mobile.page.UsersPage;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

@ExtendWith(MobileExtension.class)
@MobileUser(TestAccount.RESERVATION)
public class ReservationTest {
    @Inject
    private UsersPage usersPage;

    @Inject
    private DbClient dbClient;

    @Inject
    private LoginPage loginPage;

    @Test
    @DisplayName("Изменение статуса резервирования подарка другого пользователя")
    void changeReservationStatus(TestContext context) {
        TestAccount.RESERVATION_OWNER.dataPreparation().accept(dbClient, TestAccount.RESERVATION_OWNER.username());
        loginPage.login(context.account());

        usersPage.open();
        usersPage.filterByUsername(TestAccount.RESERVATION_OWNER.username());
        usersPage.openUser(TestAccount.RESERVATION_OWNER.username());
        usersPage.openFirstWishlist();
        usersPage.openFirstGift();
        boolean before = usersPage.isReserved();
        usersPage.toggleReservation();
        assertNotEquals(before, usersPage.isReserved(), "Reservation status was not changed");
    }
}
