import { GuestInvitePage, InviteGuestModalPage, LoginPage } from '@admin-lib/index';
import { guestInfoData } from '@fixtures/admin/guest_data';
import { User_Type } from '@support-onboard/index';
import { CompanyCustomFields, CustomFieldsUtility } from '@utility-lib/index';

describe('GME: manage guest invites for external users', () => {
  beforeEach(() => {
    const companyCustomFields: CompanyCustomFields = new Map();
    companyCustomFields.set('projects', [
      CustomFieldsUtility.initCustomFieldOption({
        label: guestInfoData.project
      })
    ]);
    companyCustomFields.set('billToClient', [
      CustomFieldsUtility.initCustomFieldOption({
        label: guestInfoData.billToClient
      })
    ]);
    companyCustomFields.set('tripPurpose', [
      CustomFieldsUtility.initCustomFieldOption({
        label: guestInfoData.tripPurpose
      })
    ]);

    LoginPage.createNewCompanyAndLoginWithUserByType({
      users: [User_Type.ADMIN],
      companyCustomFields: companyCustomFields
    });

    cy.createGuestInvitePaymentMethod();
  });

  it('C51006: Verify Manage Invites page', { tags: ['@tier1'] }, () => {
    GuestInvitePage.visitGuestInvitePage();
    GuestInvitePage.selectGuestInviteOption();
    InviteGuestModalPage.fillGuestInfo({
      firstName: guestInfoData.firstName,
      lastName: guestInfoData.lastName,
      email: guestInfoData.email,
      costCenter: guestInfoData.guestCostCenter,
      department: guestInfoData.guestDepartment
    });
    InviteGuestModalPage.selectNextOptionFromGuestInformation();
    InviteGuestModalPage.setEventName(guestInfoData.eventName);
    InviteGuestModalPage.setEventLocation(guestInfoData.eventLocation);
    InviteGuestModalPage.selectNextOptionFromEventDetails();
    InviteGuestModalPage.setAdditionalInfo(guestInfoData.additionalInfo);
    InviteGuestModalPage.selectNextOptionFromTravelPolicy();
    InviteGuestModalPage.selectPaymentMethod(guestInfoData.paymentMethod);
    InviteGuestModalPage.selectTripPurpose(guestInfoData.tripPurpose);
    InviteGuestModalPage.selectBillToClient(guestInfoData.billToClient);
    InviteGuestModalPage.selectProjects(guestInfoData.project);
    InviteGuestModalPage.selectReviewOption();
    InviteGuestModalPage.selectOnlyInviteOption();
    InviteGuestModalPage.verifyInvitationSuccessMessage();
    GuestInvitePage.searchEventByEventName(guestInfoData.eventName);
    GuestInvitePage.verifyCreatedEventData(guestInfoData.eventName, guestInfoData.email);
  });

  afterEach(() => {
    // TODO: we do not allow to revoke fully booked invitation
    // option 1: remove this code
    // option 2: add logic to revoke fully booked invitation
    // option 3: add more allowed verticals so that invitation is not fully booked
    // cy.revokeInvitation();
    // cy.deletePaymentMethod();
  });
});
