package me.pagarme;

import org.junit.Assert;

import me.pagar.model.Address;
import me.pagar.model.CompaniesTemporary;
import me.pagar.model.Customer;
import me.pagar.model.PagarMe;
import me.pagar.model.Phone;
import me.pagar.model.Transaction;

public abstract class BaseTest {

    protected Transaction transaction;
    protected Customer customer;

    protected static String NAME = "Teste Create Customer";
    protected static String DOCUMENT_NUMBER = "84344469283";
    protected static String EMAIL = "testcreatecustomer@pagar.me";
    protected static String STREET = "Rua Piraju";
    protected static String STREET_NUMBER = "218";
    protected static String COMPLEMENTARY = "ao lado da consigáz";
    protected static String NEIGHBORHOOD = "Interlagos";
    protected static String ZIP_CODE = "04840110";
    protected static String PHONE_DDD = "11";
    protected static String PHONE_NUMBER = "55284132";

    protected static Integer TRANSFER_DAY = 1;
    protected static Boolean TRANSFER_ENABLE = true;

    /*
        API Version 2017-08-28
    */

    protected static final String DEFAULT_EXTERNAL_ID = "12345666";
    protected static final String DEFAULT_NAME = "Theo Emanuel Felipe Oliveira";
    protected static final Customer.Type DEFAULT_TYPE = Customer.Type.INDIVIDUAL;
    protected static final String DEFAULT_COUNTRY = "br";
    protected static final String DEFAULT_EMAIL = "theo.emanuel.oliveira@negocios-de-valor.com";
    protected static final String DEFAULT_BIRTHDAY = "1994-11-05";

    public void setUp() {
        transaction = new Transaction();

        PagarMe.init("test_key");
        String apiKey = new CompaniesTemporary().getTemporaryCompanyApiKey("2013-03-01");
        PagarMe.init(apiKey);
    }

    public void setUp(String apiVersion) {
        transaction = new Transaction();

        PagarMe.init("test_key");
        String apiKey = new CompaniesTemporary().getTemporaryCompanyApiKey(apiVersion);
        PagarMe.init(apiKey);
    }

    /**
     *
     * @return
     */
    protected Customer customerCommon() {
        Customer customer = new Customer();
        customer.setName("lucas santos");
        customer.setDocumentNumber("15317529506");
        customer.setEmail("testelibjava@pagar.me");

        return customer;
    }

    /**
     *
     * @return
     */
    protected Address addressCommon() {
        Address address = new Address();
        address.setStreet("Rua Piraju");
        address.setStreetNumber("218");
        address.setComplementary("ao lado da consigáz");
        address.setNeighborhood("Interlagos");
        address.setZipcode("04840110");

        return address;
    }

    /**
     *
     * @return
     */
    protected Phone phoneCommon() {
        Phone phone = new Phone();
        phone.setDdd("11");
        phone.setNumber("55284132");

        return phone;
    }

    /**
     *
     * @return
     */
    protected Customer customerCreateCommon() {
        Customer customer = new Customer();
        customer.setName(NAME);
        customer.setDocumentNumber(DOCUMENT_NUMBER);
        customer.setEmail(EMAIL);

        Address address = new Address();
        address.setStreet(STREET);
        address.setStreetNumber(STREET_NUMBER);
        address.setComplementary(COMPLEMENTARY);
        address.setNeighborhood(NEIGHBORHOOD);
        address.setZipcode(ZIP_CODE);

        Phone phone = new Phone();
        phone.setDdd(PHONE_DDD);
        phone.setNumber(PHONE_NUMBER);

        customer.setAddress(address);
        customer.setPhone(phone);

        return customer;
    }

    /**
     *
     * @param customer
     * @param customerAddress
     * @param customerPhone
     */
    protected void assertCustomer(Customer customer, Address customerAddress, Phone customerPhone) {
        this.assertCustomerData(customer);
        this.assertAddress(customerAddress);
        this.assertPhone(phoneCommon());
    }

    /**
     *
     * @param customer
     */
    protected void assertCustomer(Customer customer) {
        Assert.assertEquals(DEFAULT_EXTERNAL_ID, customer.getExternalId());
        Assert.assertEquals(DEFAULT_NAME, customer.getName());
        Assert.assertEquals(DEFAULT_TYPE, customer.getType());
        Assert.assertEquals(DEFAULT_COUNTRY, customer.getCountry());
        Assert.assertEquals(DEFAULT_EMAIL, customer.getEmail());
        Assert.assertEquals(DEFAULT_BIRTHDAY, customer.getBirthday());
        Assert.assertEquals(1, customer.getDocuments().size());
        Assert.assertEquals(2, customer.getPhoneNumbers().size());
    }

    /**
     *
     * @param customer
     */
    protected void assertCustomerData(Customer customer) {

        Assert.assertEquals(customer.getName(), NAME);
        Assert.assertEquals(customer.getDocumentNumber(), DOCUMENT_NUMBER);
        Assert.assertEquals(customer.getEmail(), EMAIL);
    }

    /**
     *
     * @param customerAddress
     */
    protected void assertAddress(Address customerAddress) {

        Assert.assertEquals(customerAddress.getStreet(), STREET);
        Assert.assertEquals(customerAddress.getStreetNumber(), STREET_NUMBER);
        Assert.assertEquals(customerAddress.getComplementary(), COMPLEMENTARY);
        Assert.assertEquals(customerAddress.getNeighborhood(), NEIGHBORHOOD);
        Assert.assertEquals(customerAddress.getZipcode(), ZIP_CODE);
    }

    /**
     *
     * @param customerPhone
     */
    protected void assertPhone(Phone customerPhone) {
        Assert.assertEquals(customerPhone.getDdd(), PHONE_DDD);
        Assert.assertEquals(customerPhone.getNumber(), PHONE_NUMBER);
    }
}

@@ -239,16 +239,59 @@
 saction;
+%0Aimport me.pagarme.factory.CustomerFactory;
 %0A%0Apublic
@@ -389,16 +389,87 @@
 ustomer;
+%0A    protected CustomerFactory customerFactory = new CustomerFactory();
 %0A%0A    pr
@@ -1134,508 +1134,8 @@
 e;%0A%0A
-    /*%0A        API Version 2017-08-28%0A    */%0A%0A    protected static final String DEFAULT_EXTERNAL_ID = %2212345666%22;%0A    protected static final String DEFAULT_NAME = %22Theo Emanuel Felipe Oliveira%22;%0A    protected static final Customer.Type DEFAULT_TYPE = Customer.Type.INDIVIDUAL;%0A    protected static final String DEFAULT_COUNTRY = %22br%22;%0A    protected static final String DEFAULT_EMAIL = %22theo.emanuel.oliveira@negocios-de-valor.com%22;%0A    protected static final String DEFAULT_BIRTHDAY = %221994-11-05%22;%0A%0A
     
@@ -3661,47 +3661,102 @@
     
-Assert.assertEquals(DEFAULT_EXTERNAL_ID
+customer = customerFactory.createApiV3();%0A        Assert.assertEquals(customer.getExternalId()
 , cu
@@ -3812,20 +3812,26 @@
 als(
-DEFAULT_NAME
+customer.getName()
 , cu
@@ -3881,20 +3881,26 @@
 als(
-DEFAULT_TYPE
+customer.getType()
 , cu
@@ -3950,23 +3950,29 @@
 als(
-DEFAULT_COUNTRY
+customer.getCountry()
 , cu
@@ -4025,21 +4025,27 @@
 als(
-DEFAULT_EMAIL
+customer.getEmail()
 , cu
@@ -4096,24 +4096,30 @@
 als(
-DEFAULT_BIRTHDAY
+customer.getBirthday()
 , cu

refactor customer tests using customer factory