import { environment } from "../../src/environments/environment";

export class PublicSubmissionPage {
    baseUrl: string = environment.api.baseUrl;
    constructor() {
        // Get form data
        cy.intercept('POST', `${this.baseUrl}/form-data`, { fixture: 'form-data.json' })
            .as('getFormData');

        cy.intercept('GET', `${this.baseUrl}/company?page=1&limit=10`, { fixture: 'companies.json' })
            .as('getCompanies');
    }

    public visit(): void {
        cy.visit('/submit');
    }
    public nextStep(): void {
        cy.byTestId('next-step').first().click({ force: true });
    }

    public uploadPrescriptionFile(): void {
        cy.byTestId('file-uploader-file')
            .attachFile('sample.pdf');

        cy.byTestId("file-uploader-upload-button")
            .click({ force: true });
    }

    public confirmAndSave(): void {
        cy.byTestId('save-button').click({ force: true });
        cy.byTestId('confirm-button').click({ force: true });
    }

    public cancel(): void {
        cy.byTestId('cancel-button').click({ force: true });
    }


    public submitForMe(): void {

        cy.wait('@getFormData');

        cy.byTestId('customer-title')
            .click({ force: true })
            .get('mat-option')
            .contains('Mrs')
            .click({ force: true });

        cy.byTestId('customer-initials')
            .clear({ force: true })
            .type('BS', { force: true });

        cy.byTestId('customer-first-name')
            .clear()
            .type('Beth');

        cy.byTestId('customer-last-name')
            .clear()
            .type('Smith');

        cy.byTestId('customer-gender')
            .click({ force: true })
            .get('mat-option')
            .contains('Female')
            .click({ force: true });

        cy.byTestId('customer-date-of-birth')
            .clear()
            .type('3/4/1991');

        cy.byTestId('customer-phone-number')
            .clear()
            .type('0782123789')

        cy.byTestId('customer-alternative-phone-number')
            .clear()
            .type('0779123789')


        cy.byTestId('customer-for-who')
            .click({ force: true })
            .get('mat-option')
            .contains('Me')
            .click({ force: true });

        this.nextStep();

        cy.byTestId('self-number-of-dependants')
            .clear({ force: true })
            .type('3', { force: true });

        cy.byTestId('self-country')
            .click({ force: true })
            .get('mat-option')
            .contains('South Africa')
            .click({ force: true });

        cy.byTestId('self-province')
            .click({ force: true })
            .get('mat-option')
            .contains('Gauteng')
            .click({ force: true });

        cy.byTestId('self-address-line-1')
            .clear({ force: true })
            .type('1234 Fake Street', { force: true });

        cy.byTestId('self-address-line-2')
            .clear({ force: true })
            .type('5678 Another Fake Street', { force: true });

        cy.byTestId('self-building-apt-number')
            .clear({ force: true })
            .type('12', { force: true });

        cy.byTestId('self-postcode')
            .clear({ force: true })
            .type('1234', { force: true });

        cy.byTestId('self-delivery-type')
            .click({ force: true })
            .get('mat-option')
            .contains('Delivery')
            .click({ force: true });

        this.confirmAndSave();

        this.uploadPrescriptionFile();
    }

    submitForSomeOneElse() {
        cy.wait('@getFormData');

        cy.byTestId('customer-title')
            .click({ force: true })
            .get('mat-option')
            .contains('Mrs')
            .click({ force: true });

        cy.byTestId('customer-initials')
            .clear({ force: true })
            .type('BS', { force: true });

        cy.byTestId('customer-first-name')
            .clear()
            .type('Beth');

        cy.byTestId('customer-last-name')
            .clear()
            .type('Smith');

        cy.byTestId('customer-gender')
            .click({ force: true })
            .get('mat-option')
            .contains('Female')
            .click({ force: true });

        cy.byTestId('customer-date-of-birth')
            .clear()
            .type('3/4/1991');

        cy.byTestId('customer-phone-number')
            .clear()
            .type('0782123789')

        cy.byTestId('customer-alternative-phone-number')
            .clear()
            .type('0779123789')


        cy.byTestId('customer-for-who')
            .click({ force: true })
            .get('mat-option')
            .contains('Some one else')
            .click({ force: true });

        this.nextStep();

        cy.byTestId('individual-title')
            .click({ force: true })
            .get('mat-option')
            .contains('Mrs')
            .click({ force: true });

        cy.byTestId('individual-initials')
            .clear({ force: true })
            .type('BS', { force: true });

        cy.byTestId('individual-first-name')
            .clear()
            .type('Beth');

        cy.byTestId('individual-last-name')
            .clear()
            .type('Smith');

        cy.byTestId('individual-gender')
            .click({ force: true })
            .get('mat-option')
            .contains('Female')
            .click({ force: true });

        cy.byTestId('individual-is-animal')
            .click({ force: true })
            .get('mat-option')
            .contains('Yes')
            .click({ force: true });

        cy.byTestId('individual-date-of-birth')
            .clear()
            .type('3/4/1991');

        cy.byTestId('individual-phone-number')
            .clear()
            .type('0782123789')


        cy.byTestId('individual-number-of-dependants')
            .clear({ force: true })
            .type('10', { force: true });


        cy.byTestId('individual-country')
            .click({ force: true })
            .get('mat-option')
            .contains('South Africa')
            .click({ force: true });

        cy.byTestId('individual-province')
            .click({ force: true })
            .get('mat-option')
            .contains('Gauteng')
            .click({ force: true });

        cy.byTestId('individual-address-line-1')
            .clear({ force: true })
            .type('1234 Fake Street', { force: true });

        cy.byTestId('individual-address-line-2')
            .clear({ force: true })
            .type('5678 Another Fake Street', { force: true });

        cy.byTestId('individual-building-apt-number')
            .clear({ force: true })
            .type('12', { force: true });

        cy.byTestId('individual-postcode')
            .clear({ force: true })
            .type('1234', { force: true });

        cy.byTestId('individual-delivery-type')
            .click({ force: true })
            .get('mat-option')
            .contains('Delivery')
            .click({ force: true });

        this.confirmAndSave();

        this.uploadPrescriptionFile();
    }

    submitForCompany() {
        cy.wait('@getFormData');

        cy.byTestId('customer-title')
            .click({ force: true })
            .get('mat-option')
            .contains('Mrs')
            .click({ force: true });

        cy.byTestId('customer-initials')
            .clear({ force: true })
            .type('BS', { force: true });

        cy.byTestId('customer-first-name')
            .clear()
            .type('Beth');

        cy.byTestId('customer-last-name')
            .clear()
            .type('Smith');

        cy.byTestId('customer-gender')
            .click({ force: true })
            .get('mat-option')
            .contains('Female')
            .click({ force: true });

        cy.byTestId('customer-date-of-birth')
            .clear()
            .type('3/4/1991');

        cy.byTestId('customer-phone-number')
            .clear()
            .type('0782123789')

        cy.byTestId('customer-alternative-phone-number')
            .clear()
            .type('0779123789')


        cy.byTestId('customer-for-who')
            .click({ force: true })
            .get('mat-option')
            .contains('Company')
            .click({ force: true });

        this.nextStep();

        cy.byTestId('self-number-of-dependants')
            .clear({ force: true })
            .type('3', { force: true });

        cy.byTestId('self-country')
            .click({ force: true })
            .get('mat-option')
            .contains('South Africa')
            .click({ force: true });

        cy.byTestId('self-province')
            .click({ force: true })
            .get('mat-option')
            .contains('Gauteng')
            .click({ force: true });

        cy.byTestId('self-address-line-1')
            .clear({ force: true })
            .type('1234 Fake Street', { force: true });

        cy.byTestId('self-address-line-2')
            .clear({ force: true })
            .type('5678 Another Fake Street', { force: true });

        cy.byTestId('self-building-apt-number')
            .clear({ force: true })
            .type('12', { force: true });

        cy.byTestId('self-postcode')
            .clear({ force: true })
            .type('1234', { force: true });

        cy.byTestId('self-delivery-type')
            .click({ force: true })
            .get('mat-option')
            .contains('Delivery')
            .click({ force: true });

        this.nextStep();

        cy.byTestId('company-name')
            .clear({ force: true })
            .type('Microsoft', { force: true });

        cy.byTestId('company-email')
            .clear({ force: true })
            .type('user@microsoft.com', { force: true });

        cy.byTestId('company-email-alt')
            .clear({ force: true })
            .type('user@outlook.com', { force: true });

        cy.byTestId('company-phone-number')
            .clear({ force: true })
            .type('0782841339', { force: true });

        cy.byTestId('company-alternative-phone-number')
            .clear({ force: true })
            .type('0782841339', { force: true });

        cy.byTestId('company-practice-number')
            .clear({ force: true })
            .type('1234567890', { force: true });

        cy.byTestId('company-vat-reg-number')
            .clear({ force: true })
            .type('1234567890', { force: true });

        cy.byTestId('company-type')
            .click({ force: true })
            .get('mat-option')
            .contains('Doctor\'s Practice')
            .click({ force: true });

        cy.byTestId('company-country')
            .click({ force: true })
            .get('mat-option')
            .contains('South Africa')
            .click({ force: true });

        cy.byTestId('company-province')
            .click({ force: true })
            .get('mat-option')
            .contains('Gauteng')
            .click({ force: true });

        cy.byTestId('company-address-line-1')
            .clear({ force: true })
            .type('1234 Fake Street');

        cy.byTestId('company-address-line-2')
            .clear({ force: true })
            .type('5678 Another Fake Street');

        cy.byTestId('company-building-apt-number')
            .clear({ force: true })
            .type('1', { force: true })

        cy.byTestId('company-postcode')
            .clear({ force: true })
            .type('1234', { force: true })

        this.confirmAndSave();

        this.uploadPrescriptionFile();

    }
}