package com.zhaohaoting.framework.imagepicker.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

/**
 * ================================================
 * 作    者：jeasonlzy（廖子尧 Github地址：https://github.com/jeasonlzy0216
 * 版    本：1.0
 * 创建日期：2016/5/19
 * 描    述：图片信息
 * 修订历史：
 * ================================================
 */
public class MediaItem implements Serializable, Parcelable {

    public String name = "";       //图片的名字
    public String path = "";       //图片的路径
    public long size;         //图片的大小
    public int width;         //图片的宽度
    public int height;        //图片的高度
    public String mimeType;   //图片的类型
    public int mediaType;   //类型
    public long addTime;      //图片的创建时间
    public long mediaId;
    public long mediaTitle;
    public long videoDuration;//视频独有
    public String thumbnailPath = "";//缩略图

    //扩展字段
    public boolean isNetWork = false;//是否是网络图片
    public String id = "";

    public void setName(String name) {
        this.name = name;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public void setAddTime(long addTime) {
        this.addTime = addTime;
    }

    /**
     * 图片的路径和创建时间相同就认为是同一张图片
     */
    @Override
    public boolean equals(Object o) {
        if (o instanceof MediaItem) {
            MediaItem item = (MediaItem) o;
            return this.path.equalsIgnoreCase(item.path) && this.addTime == item.addTime && this.id.equals(item.id) && this.mediaId == item.mediaId;
        }

        return super.equals(o);
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.path);
        dest.writeLong(this.size);
        dest.writeInt(this.width);
        dest.writeInt(this.height);
        dest.writeString(this.mimeType);
        dest.writeLong(this.addTime);
    }

    public MediaItem() {
    }

    public MediaItem(String path, int mediaType) {
        this.path = path;
        this.mediaType = mediaType;
    }

    protected MediaItem(Parcel in) {
        this.name = in.readString();
        this.path = in.readString();
        this.size = in.readLong();
        this.width = in.readInt();
        this.height = in.readInt();
        this.mimeType = in.readString();
        this.addTime = in.readLong();
    }

    public static final Creator<MediaItem> CREATOR = new Creator<MediaItem>() {
        @Override
        public MediaItem createFromParcel(Parcel source) {
            return new MediaItem(source);
        }

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

    public void setImageItem(MediaItem imageItem) {
        this.name = imageItem.name;
        this.path = imageItem.path;
        this.size = imageItem.size;
        this.width = imageItem.width;
        this.height = imageItem.height;
        this.mimeType = imageItem.mimeType;
        this.addTime = imageItem.addTime;
    }
}
