import PagedDataProvider from 'bitbucket/internal/impl/data-provider/paged';

import validator from '../json-validation/json-validation';
import models from '../models/models';

/**
 * Provides data for a list of pull requests.
 *
 * Implementers should transform data to a {@link models.pullrequest}
 */
export default class PullRequestListDataProvider extends PagedDataProvider {

    constructor(options = {}, ...args) {

        /**
         * We extend the pull_request model with commentCount and taskCount
         */
        options.jsonDescriptor = [models.pull_request];

        /**
         * @type {Object}
         * @property {string?} author_id - the author's username
         * @property {string?} target_ref_id - the ref string, e.g. refs/heads/
         * @property {string?} reviewer_id - the reviewer's username
         * @property {string?} query - title / description substring search
         * @property {models.PullRequestState?} state
         */
        options.filterDescriptor = {
            author_id: 'string?',
            query: 'string?',
            target_ref_id: 'string?',
            reviewer_id: 'string?',
            state: validator.asEnum('PullRequestState', models.PullRequestState),
        };
        super(options, ...args);
    }


}
