<?php

/*
 * Copyright 2011 OneDrive Inc.
 *
 * 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.
 */

/**
 * Service definition for Search (v1.0).
 *
 * <p>
 * Provides access to the Microsoft Graph search/query endpoint.
 * </p>
 *
 * @see https://docs.microsoft.com/graph/api/search-query?view=graph-rest-1.0
 */
class SODOneDrive_Service_Search extends SODOneDrive_Service
{
    /**
     * The "query" collection of methods.
     * Typical usage:
     *   $search = new SODOneDrive_Service_Search($client);
     *   $response = $search->search->query($body, $optParams);.
     */
    public $search;
    public $serviceName;

    /**
     * Constructs the Search service.
     */
    public function __construct(SODOneDrive_Client $client)
    {
        parent::__construct($client);
        $this->servicePath = 'v1.0/search/';
        $this->version = 'v1.0';
        $this->serviceName = 'search';

        $this->search = new SODOneDrive_Service_Search_Query_Resource(
            $this,
            $this->serviceName,
            'query',
            [
                'methods' => [
                    'query' => [
                        'path' => 'query',
                        'httpMethod' => 'POST',
                        'parameters' => [],
                    ],
                ],
            ]
        );
    }
}

/**
 * The "query" collection of methods.
 */
class SODOneDrive_Service_Search_Query_Resource extends SODOneDrive_Service_Resource
{
    /**
     * Executes a search query.
     *
     * @param array|object $postBody  the search request payload
     * @param array        $optParams optional query parameters
     *
     * @return SODOneDrive_Service_Search_Search
     */
    public function query($postBody, $optParams = [])
    {
        $params = ['postBody' => $postBody];
        $params = array_merge($params, $optParams);

        return $this->call('query', [$params], 'SODOneDrive_Service_Search_Search');
    }
}

/**
 * Updated response model for a search query.
 */
class SODOneDrive_Service_Search_Search extends SODOneDrive_Collection
{
    protected $valueType = 'SODOneDrive_Service_Search_SearchResponse';
    protected $valueDataType = 'array';

    public function setValue(SODOneDrive_Service_Search_SearchResponse $value)
    {
        $this->value = $value;
    }

    public function getValue()
    {
        return $this->value;
    }
}

/**
 * Updated response model for a search query.
 */
class SODOneDrive_Service_Search_SearchResponse extends SODOneDrive_Model
{
    /**
     * @var array
     */
    public $searchTerms;

    protected $hitsContainersType = 'SODOneDrive_Service_Search_HitsContainers';
    protected $hitsContainersDataType = 'array';

    public function setHitsContainers(SODOneDrive_Service_Search_HitsContainers $hitsContainers)
    {
        $this->hitsContainers = $hitsContainers;
    }

    public function getHitsContainers()
    {
        return $this->hitsContainers;
    }

    /**
     * @param array $searchTerms
     */
    public function setSearchTerms($searchTerms)
    {
        $this->searchTerms = $searchTerms;
    }

    /**
     * @return array
     */
    public function getSearchTerms()
    {
        return $this->searchTerms;
    }
}

/**
 * Updated response model for a search query.
 */
class SODOneDrive_Service_Search_HitsContainers extends SODOneDrive_Model
{
    protected $hitsType = 'SODOneDrive_Service_Search_SearchHit';
    protected $hitsDataType = 'array';

    public function setHits(SODOneDrive_Service_Search_SearchHit $hits)
    {
        $this->hits = $hits;
    }

    public function getHits()
    {
        return $this->hits;
    }

    public function setTotal($total)
    {
        $this->total = $total;
    }

    public function getTotal()
    {
        return $this->total;
    }

    public function setMoreResultsAvailable($moreResultsAvailable)
    {
        $this->moreResultsAvailable = $moreResultsAvailable;
    }

    public function getMoreResultsAvailable()
    {
        return $this->moreResultsAvailable;
    }
}

/**
 * Represents a single search hit.
 */
class SODOneDrive_Service_Search_SearchHit extends SODOneDrive_Model
{
    /**
     * @var string
     */
    public $id;

    /**
     * @var string
     */
    public $title;

    /**
     * @var string
     */
    public $summary;

    public $resourceType = 'SODOneDrive_Service_Drive_Item';
    public $resourceDataType = '';

    /**
     * @var string
     */
    public $hitId;

    /**
     * @var int
     */
    public $rank;

    /**
     * @param string $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param string $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param string $summary
     */
    public function setSummary($summary)
    {
        $this->summary = $summary;
    }

    /**
     * @return string
     */
    public function getSummary()
    {
        return $this->summary;
    }

    public function setResource(SODOneDrive_Service_Drive_Item $resource)
    {
        $this->resource = $resource;
    }

    /**
     * @return SODOneDrive_Service_Drive_Item
     */
    public function getResource()
    {
        return $this->resource;
    }

    /**
     * @param string $hitId
     */
    public function setHitId($hitId)
    {
        $this->hitId = $hitId;
    }

    /**
     * @return string
     */
    public function getHitId()
    {
        return $this->hitId;
    }

    /**
     * @param int $rank
     */
    public function setRank($rank)
    {
        $this->rank = $rank;
    }

    /**
     * @return int
     */
    public function getRank()
    {
        return $this->rank;
    }
}
