package ch.pizzalemon.android.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import ch.pizzalemon.android.api.ApiConstants;

/**
 * Created by cimenmus on 17/10/2017.
 */

public class PaymentMethodModel {

    private String code;
    private String title;
    private String terms;
    private boolean isSelected;

    @Expose @SerializedName("sort_order")
    private String sortOrder;

    public enum PaymentMethodType {
        CREDIT_DEBIT_CARD,
        CASH,
        TRANSFER,
        PAYPAL,
        TWINT,
        POST_FINANCE_CARD,
        ANDROID_PAY,
        APPLE_PAY,
        UNKNOWN
    }

    private void checkNull(){

        if(code == null)
            code = "";

        if(title == null)
            title = "";

        if(terms == null)
            terms = "";

        if(sortOrder == null)
            sortOrder = "0";
    }

    public static void checkNull(ArrayList<PaymentMethodModel> paymentMethodList){
        for(PaymentMethodModel paymentMethodModel : paymentMethodList){
            paymentMethodModel.checkNull();
        }
    }

    public static void sort(ArrayList<PaymentMethodModel> paymentMethodList){
        Collections.sort(paymentMethodList, new Comparator<PaymentMethodModel>() {
            @Override
            public int compare(PaymentMethodModel pm1, PaymentMethodModel pm2){
                return  Integer.valueOf(pm1.sortOrder).compareTo(Integer.valueOf(pm2.sortOrder));
            }
        });
    }


    public PaymentMethodType getPaymentMethodType() {
        switch (code){
            case ApiConstants.PAYMENT_METHOD_CODE_CREDIT_DEBIT_CARD:
                return PaymentMethodType.CREDIT_DEBIT_CARD;
            case ApiConstants.PAYMENT_METHOD_CODE_BANK_CASH:
                return PaymentMethodType.CASH;
            case ApiConstants.PAYMENT_METHOD_CODE_TRANSFER:
                return PaymentMethodType.TRANSFER;
            case ApiConstants.PAYMENT_METHOD_CODE_PAYPAL:
                return PaymentMethodType.PAYPAL;
            case ApiConstants.PAYMENT_METHOD_CODE_TWINT:
                return PaymentMethodType.TWINT;
            case ApiConstants.PAYMENT_METHOD_CODE_POST_FINANCE_CARD:
                return PaymentMethodType.POST_FINANCE_CARD;
            case ApiConstants.PAYMENT_METHOD_CODE_ANDROID_PAY:
                return PaymentMethodType.ANDROID_PAY;
            case ApiConstants.PAYMENT_METHOD_CODE_APPLE_PAY:
                return PaymentMethodType.APPLE_PAY;
            default:
                return PaymentMethodType.UNKNOWN;
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTerms() {
        return terms;
    }

    public void setTerms(String terms) {
        this.terms = terms;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setSelected(boolean selected) {
        isSelected = selected;
    }

    public String getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(String sortOrder) {
        this.sortOrder = sortOrder;
    }
}
