package com.smaato.sdk.demoapp.banner;

import android.os.Parcel;
import android.support.annotation.NonNull;

import com.smaato.sdk.banner.ad.BannerAdSize;
import com.smaato.sdk.demoapp.AdConfig;

import java.util.Arrays;

public class BannerAdConfig extends AdConfig {
    @NonNull
    BannerAdSize bannerAdSize;

    BannerAdConfig(@NonNull String name, @NonNull String publisherId, @NonNull String adSpaceId, @NonNull BannerAdSize bannerAdSize) {
        super(name, publisherId, adSpaceId);
        this.bannerAdSize = bannerAdSize;
    }

    private BannerAdConfig(@NonNull Parcel in) {
        super(in);
        bannerAdSize = BannerAdSize.values()[in.readInt()];
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof AdConfig)) {
            return false;
        }
        BannerAdConfig adConfig = (BannerAdConfig) o;
        return name.equals(adConfig.name) &&
                publisherId.equals(publisherId) &&
                adSpaceId.equals(adConfig.adSpaceId) &&
                bannerAdSize.toString().equals(adConfig.bannerAdSize.toString());
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(new String[]{name, publisherId, adSpaceId, bannerAdSize.toString()});
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeInt(bannerAdSize.ordinal());
    }

    public static final Creator<BannerAdConfig> CREATOR = new Creator<BannerAdConfig>() {
        @Override
        @NonNull
        public BannerAdConfig createFromParcel(@NonNull Parcel in) {
            return new BannerAdConfig(in);
        }

        @Override
        @NonNull
        public BannerAdConfig[] newArray(int size) {
            return new BannerAdConfig[size];
        }
    };
}
