/*
 * Copyright 2017 Yan Zhenjie.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sobot.album.api;

import android.content.Context;
import android.content.Intent;

import androidx.annotation.IntRange;

import com.sobot.album.AlbumFile;
import com.sobot.album.Filter;
import com.sobot.album.SobotAlbum;
import com.sobot.album.app.album.AlbumActivity;

import java.util.ArrayList;

public final class VideoMultipleWrapper extends BasicChoiceVideoWrapper<VideoMultipleWrapper, ArrayList<AlbumFile>, String, ArrayList<AlbumFile>> {

    private int mLimitCount = Integer.MAX_VALUE;
    private Filter<Long> mDurationFilter;

    public VideoMultipleWrapper(Context context) {
        super(context);
    }

    /**
     * Set the list has been selected.
     *
     * @param checked the data list.
     */
    public final VideoMultipleWrapper checkedList(ArrayList<AlbumFile> checked) {
        this.mChecked = checked;
        return this;
    }

    /**
     * Set the maximum number to be selected.
     *
     * @param count the maximum number.
     */
    public VideoMultipleWrapper selectCount(@IntRange(from = 1, to = Integer.MAX_VALUE) int count) {
        this.mLimitCount = count;
        return this;
    }

    /**
     * Filter video duration.
     *
     * @param filter filter.
     */
    public VideoMultipleWrapper filterDuration(Filter<Long> filter) {
        this.mDurationFilter = filter;
        return this;
    }

    @Override
    public void start() {
        AlbumActivity.sSizeFilter = mSizeFilter;
        AlbumActivity.sMimeFilter = mMimeTypeFilter;
        AlbumActivity.sDurationFilter = mDurationFilter;
        AlbumActivity.sResult = mResult;
        AlbumActivity.sCancel = mCancel;
        Intent intent = new Intent(mContext, AlbumActivity.class);
        intent.putExtra(SobotAlbum.KEY_INPUT_WIDGET, mWidget);
        intent.putParcelableArrayListExtra(SobotAlbum.KEY_INPUT_CHECKED_LIST, mChecked);

        intent.putExtra(SobotAlbum.KEY_INPUT_FUNCTION, SobotAlbum.FUNCTION_CHOICE_VIDEO);
        intent.putExtra(SobotAlbum.KEY_INPUT_CHOICE_MODE, SobotAlbum.MODE_MULTIPLE);
        intent.putExtra(SobotAlbum.KEY_INPUT_COLUMN_COUNT, mColumnCount);
        intent.putExtra(SobotAlbum.KEY_INPUT_ALLOW_CAMERA, mHasCamera);
        intent.putExtra(SobotAlbum.KEY_INPUT_LIMIT_COUNT, mLimitCount);
        intent.putExtra(SobotAlbum.KEY_INPUT_FILTER_VISIBILITY, mFilterVisibility);
        intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_QUALITY, mQuality);
        intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_DURATION, mLimitDuration);
        intent.putExtra(SobotAlbum.KEY_INPUT_CAMERA_BYTES, mLimitBytes);
        mContext.startActivity(intent);
    }
}