<?php
/**
 * SaleApi
 * PHP version 5
 *
 * @category Class
 * @package  ColorMeShop\Swagger
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * カラーミーショップ API
 *
 * # カラーミーショップ API  ## 利用手順  ### OAuthアプリケーションの登録  デベロッパーアカウントをお持ちでない場合は作成します。[デベロッパー登録ページ](https://api.shop-pro.jp/developers/sign_up)から登録してください。  次に、[登録ページ](https://api.shop-pro.jp/oauth/applications/new)からアプリ登録を行ってください。 スマートフォンのWebViewを利用する場合は、リダイレクトURIに`urn:ietf:wg:oauth:2.0:oob`を入力してください。  ### 認可  カラーミーショップアカウントの認証ページを開きます。認証ページのURLは、`https://api.shop-pro.jp/oauth/authorize`に必要なパラメータをつけたものです。  |パラメータ名|値| |---|---| |`client_id`|アプリ詳細画面で確認できるクライアントID| |`response_type`|\"code\"を指定| |`scope`| 別表参照| |`redirect_uri`|アプリ登録時に入力したリダイレクトURI|  `scope`は、以下のうち、アプリが利用したい機能をスペース区切りで指定してください。  |スコープ|機能| |---|---| |`read_products`|商品データの参照| |`write_products`|在庫データの更新| |`read_sales`|受注・顧客データの参照| |`write_sales`|受注データの更新| |`read_shop_coupons`|ショップクーポンの参照|  以下のようなURLとなります。  ``` https://api.shop-pro.jp/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&scope=read_products%20write_products ```  初めてこのページを訪れる場合は、カラーミーショップアカウントのログインIDとパスワードの入力を求められます。  ログイン後の認証ページでアプリとの連携が承認された場合は、`code`というクエリパラメータに認可コードが付与されます。承認がキャンセルされた、またはエラーが起きた場合は、 `error`パラメータにエラーの内容を表す文字列が与えられます。  アプリ登録時のリダイレクトURIに`urn:ietf:wg:oauth:2.0:oob`を指定した場合は、以下のようなURLにリダイレクトされ、 認可コードがURLの末尾に付与されます。  ``` https://api.shop-pro.jp/oauth/authorize/AUTH_CODE ```  認可コードの有効期限は発行から10分間です。  ### 認可コードをアクセストークンに交換  以下のパラメータを付けて、`https://api.shop-pro.jp/oauth/token`へリクエストを送ります。  |パラメータ名|値| |---|---| |`client_id`|アプリ詳細画面に表示されているクライアントID| |`client_secret`|アプリ詳細画面に表示されているクライアントシークレット| |`code`|取得した認可コード| |`grant_type`|\"authorization_code\"を指定| |`redirect_uri`|アプリ登録時に入力したリダイレクトURI|  curlによるリクエストの例を以下に示します。 ```console $ curl -X POST \\   -d'client_id=CLIENT_ID' \\   -d'client_secret=CLIENT_SECRET' \\   -d'code=CODE' \\   -d'grant_type=authorization_code'   \\   -d'redirect_uri=REDIRECT_URI'  \\   'https://api.shop-pro.jp/oauth/token' ```  リクエストが成功すると、以下のようなJSONが返却されます  ```json {   \"access_token\": \"d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX\",   \"token_type\": \"bearer\",   \"scope\": \"read_products write_products\" } ```  アクセストークンに有効期限はありませんが、[許可済みアプリ一覧画面](https://admin.shop-pro.jp/?mode=app_use_lst)から失効させることができます。なお、同じ認可コードをアクセストークンに交換できるのは1度だけです。  ### APIの利用  取得したアクセストークンは、Authorizationヘッダに入れて使用します。以下にショップ情報を取得する例を示します。  ```console $ curl -H 'Authorization: Bearer d461ab8XXXXXXXXXXXXXXXXXXXXXXXXX' https://api.shop-pro.jp/v1/shop.json ```  ## エラー  カラーミーショップAPIでは、以下の形式の配列でエラーを表現します。  - `code` エラーコード - `message` エラーメッセージ - `status` ステータスコード  ```json {   \"errors\": [     {       \"code\": 404100,       \"message\": \"レコードが見つかりませんでした。\",       \"status\": 404     }   ] } ```  ## 都道府県コードについて APIを利用して都道府県コードを更新したり、レスポンスを参照される際には以下の表を参考にしてください。  <details>   <summary>都道府県コード一覧</summary>    |id|都道府県|   |---|---|   |1|北海道|   |2|青森県|   |3|岩手県|   |4|秋田県|   |5|宮城県|   |6|山形県|   |7|福島県|   |8|茨城県|   |9|栃木県|   |10|群馬県|   |11|埼玉県|   |12|千葉県|   |13|東京都|   |14|神奈川県|   |15|新潟県|   |16|福井県|   |17|石川県|   |18|富山県|   |19|静岡県|   |20|山梨県|   |21|長野県|   |22|愛知県|   |23|岐阜県|   |24|三重県|   |25|和歌山県|   |26|滋賀県|   |27|奈良県|   |28|京都府|   |29|大阪府|   |30|兵庫県|   |31|岡山県|   |32|広島県|   |33|鳥取県|   |34|島根県|   |35|山口県|   |36|香川県|   |37|徳島県|   |38|愛媛県|   |39|高知県|   |40|福岡県|   |41|佐賀県|   |42|長崎県|   |43|大分県|   |44|熊本県|   |45|宮崎県|   |46|鹿児島県|   |47|沖縄県|   |48|海外|  </details>
 *
 * OpenAPI spec version: 1.0.0
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 * Swagger Codegen version: 3.0.27
 */
/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace ColorMeShop\Swagger\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use ColorMeShop\Swagger\ApiException;
use ColorMeShop\Swagger\Configuration;
use ColorMeShop\Swagger\HeaderSelector;
use ColorMeShop\Swagger\ObjectSerializer;

/**
 * SaleApi Class Doc Comment
 *
 * @category Class
 * @package  ColorMeShop\Swagger
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class SaleApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation cancelSale
     *
     * 受注のキャンセル
     *
     * @param  int $sale_id sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdCancelBody $body body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2004
     */
    public function cancelSale($sale_id, $body = null)
    {
        list($response) = $this->cancelSaleWithHttpInfo($sale_id, $body);
        return $response;
    }

    /**
     * Operation cancelSaleWithHttpInfo
     *
     * 受注のキャンセル
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdCancelBody $body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2004, HTTP status code, HTTP response headers (array of strings)
     */
    public function cancelSaleWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2004';
        $request = $this->cancelSaleRequest($sale_id, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2004',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation cancelSaleAsync
     *
     * 受注のキャンセル
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdCancelBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelSaleAsync($sale_id, $body = null)
    {
        return $this->cancelSaleAsyncWithHttpInfo($sale_id, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation cancelSaleAsyncWithHttpInfo
     *
     * 受注のキャンセル
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdCancelBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function cancelSaleAsyncWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2004';
        $request = $this->cancelSaleRequest($sale_id, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'cancelSale'
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdCancelBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function cancelSaleRequest($sale_id, $body = null)
    {
        // verify the required parameter 'sale_id' is set
        if ($sale_id === null || (is_array($sale_id) && count($sale_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $sale_id when calling cancelSale'
            );
        }

        $resourcePath = '/v1/sales/{sale_id}/cancel';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($sale_id !== null) {
            $resourcePath = str_replace(
                '{' . 'sale_id' . '}',
                ObjectSerializer::toPathValue($sale_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'PUT',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getSale
     *
     * 受注データの取得
     *
     * @param  int $sale_id sale_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2003
     */
    public function getSale($sale_id)
    {
        list($response) = $this->getSaleWithHttpInfo($sale_id);
        return $response;
    }

    /**
     * Operation getSaleWithHttpInfo
     *
     * 受注データの取得
     *
     * @param  int $sale_id (required)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2003, HTTP status code, HTTP response headers (array of strings)
     */
    public function getSaleWithHttpInfo($sale_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2003';
        $request = $this->getSaleRequest($sale_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2003',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getSaleAsync
     *
     * 受注データの取得
     *
     * @param  int $sale_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSaleAsync($sale_id)
    {
        return $this->getSaleAsyncWithHttpInfo($sale_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getSaleAsyncWithHttpInfo
     *
     * 受注データの取得
     *
     * @param  int $sale_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSaleAsyncWithHttpInfo($sale_id)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2003';
        $request = $this->getSaleRequest($sale_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getSale'
     *
     * @param  int $sale_id (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getSaleRequest($sale_id)
    {
        // verify the required parameter 'sale_id' is set
        if ($sale_id === null || (is_array($sale_id) && count($sale_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $sale_id when calling getSale'
            );
        }

        $resourcePath = '/v1/sales/{sale_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($sale_id !== null) {
            $resourcePath = str_replace(
                '{' . 'sale_id' . '}',
                ObjectSerializer::toPathValue($sale_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getSales
     *
     * 受注データのリストを取得
     *
     * @param  string $ids 受注IDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $after 指定日時以降の受注から検索。  &#x60;after&#x60; 未指定時は &#x60;before&#x60; の指定日時の7日前の0時、  &#x60;before&#x60; 未指定時は現在から7日前の0時がデフォルト値となります。 (optional)
     * @param  string $before 指定日時以前の受注から検索 (optional)
     * @param  string $make_date_min &#x60;after&#x60;と同義 (optional)
     * @param  string $make_date_max &#x60;before&#x60;と同義 (optional)
     * @param  string $update_date_min 指定日時以降に更新された受注から検索 (optional)
     * @param  string $update_date_max 指定日時以前に更新された受注から検索 (optional)
     * @param  string $customer_ids 購入した顧客IDで検索。カンマ区切りにすることで複数検索が可能 (optional)
     * @param  string $customer_name 購入した顧客名で部分一致検索 (optional)
     * @param  string $customer_furigana 購入した顧客フリガナがで部分一致検索 (optional)
     * @param  string $customer_mail 購入した顧客メールアドレスで部分一致検索 (optional)
     * @param  string $accepted_mail_state 受注メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $paid_mail_state 入金メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $delivered_mail_state 配送メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  bool $mobile &#x60;true&#x60;なら携帯からの受注のみ取得 (optional)
     * @param  bool $paid &#x60;true&#x60;なら入金済みの受注のみ取得 (optional)
     * @param  bool $delivered &#x60;true&#x60;なら配送済みの受注のみ取得 (optional)
     * @param  bool $canceled &#x60;true&#x60;ならキャンセル済みの受注のみ取得 (optional)
     * @param  string $payment_ids 使用された決済のIDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $fields レスポンスJSONのキーをカンマ区切りで指定 (optional)
     * @param  int $limit レスポンスの件数を指定。指定がない場合は10。最大100 (optional)
     * @param  int $offset 指定した数値+1件目以降のデータを返す (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2001
     */
    public function getSales($ids = null, $after = null, $before = null, $make_date_min = null, $make_date_max = null, $update_date_min = null, $update_date_max = null, $customer_ids = null, $customer_name = null, $customer_furigana = null, $customer_mail = null, $accepted_mail_state = null, $paid_mail_state = null, $delivered_mail_state = null, $mobile = null, $paid = null, $delivered = null, $canceled = null, $payment_ids = null, $fields = null, $limit = null, $offset = null)
    {
        list($response) = $this->getSalesWithHttpInfo($ids, $after, $before, $make_date_min, $make_date_max, $update_date_min, $update_date_max, $customer_ids, $customer_name, $customer_furigana, $customer_mail, $accepted_mail_state, $paid_mail_state, $delivered_mail_state, $mobile, $paid, $delivered, $canceled, $payment_ids, $fields, $limit, $offset);
        return $response;
    }

    /**
     * Operation getSalesWithHttpInfo
     *
     * 受注データのリストを取得
     *
     * @param  string $ids 受注IDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $after 指定日時以降の受注から検索。  &#x60;after&#x60; 未指定時は &#x60;before&#x60; の指定日時の7日前の0時、  &#x60;before&#x60; 未指定時は現在から7日前の0時がデフォルト値となります。 (optional)
     * @param  string $before 指定日時以前の受注から検索 (optional)
     * @param  string $make_date_min &#x60;after&#x60;と同義 (optional)
     * @param  string $make_date_max &#x60;before&#x60;と同義 (optional)
     * @param  string $update_date_min 指定日時以降に更新された受注から検索 (optional)
     * @param  string $update_date_max 指定日時以前に更新された受注から検索 (optional)
     * @param  string $customer_ids 購入した顧客IDで検索。カンマ区切りにすることで複数検索が可能 (optional)
     * @param  string $customer_name 購入した顧客名で部分一致検索 (optional)
     * @param  string $customer_furigana 購入した顧客フリガナがで部分一致検索 (optional)
     * @param  string $customer_mail 購入した顧客メールアドレスで部分一致検索 (optional)
     * @param  string $accepted_mail_state 受注メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $paid_mail_state 入金メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $delivered_mail_state 配送メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  bool $mobile &#x60;true&#x60;なら携帯からの受注のみ取得 (optional)
     * @param  bool $paid &#x60;true&#x60;なら入金済みの受注のみ取得 (optional)
     * @param  bool $delivered &#x60;true&#x60;なら配送済みの受注のみ取得 (optional)
     * @param  bool $canceled &#x60;true&#x60;ならキャンセル済みの受注のみ取得 (optional)
     * @param  string $payment_ids 使用された決済のIDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $fields レスポンスJSONのキーをカンマ区切りで指定 (optional)
     * @param  int $limit レスポンスの件数を指定。指定がない場合は10。最大100 (optional)
     * @param  int $offset 指定した数値+1件目以降のデータを返す (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2001, HTTP status code, HTTP response headers (array of strings)
     */
    public function getSalesWithHttpInfo($ids = null, $after = null, $before = null, $make_date_min = null, $make_date_max = null, $update_date_min = null, $update_date_max = null, $customer_ids = null, $customer_name = null, $customer_furigana = null, $customer_mail = null, $accepted_mail_state = null, $paid_mail_state = null, $delivered_mail_state = null, $mobile = null, $paid = null, $delivered = null, $canceled = null, $payment_ids = null, $fields = null, $limit = null, $offset = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2001';
        $request = $this->getSalesRequest($ids, $after, $before, $make_date_min, $make_date_max, $update_date_min, $update_date_max, $customer_ids, $customer_name, $customer_furigana, $customer_mail, $accepted_mail_state, $paid_mail_state, $delivered_mail_state, $mobile, $paid, $delivered, $canceled, $payment_ids, $fields, $limit, $offset);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2001',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getSalesAsync
     *
     * 受注データのリストを取得
     *
     * @param  string $ids 受注IDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $after 指定日時以降の受注から検索。  &#x60;after&#x60; 未指定時は &#x60;before&#x60; の指定日時の7日前の0時、  &#x60;before&#x60; 未指定時は現在から7日前の0時がデフォルト値となります。 (optional)
     * @param  string $before 指定日時以前の受注から検索 (optional)
     * @param  string $make_date_min &#x60;after&#x60;と同義 (optional)
     * @param  string $make_date_max &#x60;before&#x60;と同義 (optional)
     * @param  string $update_date_min 指定日時以降に更新された受注から検索 (optional)
     * @param  string $update_date_max 指定日時以前に更新された受注から検索 (optional)
     * @param  string $customer_ids 購入した顧客IDで検索。カンマ区切りにすることで複数検索が可能 (optional)
     * @param  string $customer_name 購入した顧客名で部分一致検索 (optional)
     * @param  string $customer_furigana 購入した顧客フリガナがで部分一致検索 (optional)
     * @param  string $customer_mail 購入した顧客メールアドレスで部分一致検索 (optional)
     * @param  string $accepted_mail_state 受注メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $paid_mail_state 入金メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $delivered_mail_state 配送メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  bool $mobile &#x60;true&#x60;なら携帯からの受注のみ取得 (optional)
     * @param  bool $paid &#x60;true&#x60;なら入金済みの受注のみ取得 (optional)
     * @param  bool $delivered &#x60;true&#x60;なら配送済みの受注のみ取得 (optional)
     * @param  bool $canceled &#x60;true&#x60;ならキャンセル済みの受注のみ取得 (optional)
     * @param  string $payment_ids 使用された決済のIDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $fields レスポンスJSONのキーをカンマ区切りで指定 (optional)
     * @param  int $limit レスポンスの件数を指定。指定がない場合は10。最大100 (optional)
     * @param  int $offset 指定した数値+1件目以降のデータを返す (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSalesAsync($ids = null, $after = null, $before = null, $make_date_min = null, $make_date_max = null, $update_date_min = null, $update_date_max = null, $customer_ids = null, $customer_name = null, $customer_furigana = null, $customer_mail = null, $accepted_mail_state = null, $paid_mail_state = null, $delivered_mail_state = null, $mobile = null, $paid = null, $delivered = null, $canceled = null, $payment_ids = null, $fields = null, $limit = null, $offset = null)
    {
        return $this->getSalesAsyncWithHttpInfo($ids, $after, $before, $make_date_min, $make_date_max, $update_date_min, $update_date_max, $customer_ids, $customer_name, $customer_furigana, $customer_mail, $accepted_mail_state, $paid_mail_state, $delivered_mail_state, $mobile, $paid, $delivered, $canceled, $payment_ids, $fields, $limit, $offset)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getSalesAsyncWithHttpInfo
     *
     * 受注データのリストを取得
     *
     * @param  string $ids 受注IDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $after 指定日時以降の受注から検索。  &#x60;after&#x60; 未指定時は &#x60;before&#x60; の指定日時の7日前の0時、  &#x60;before&#x60; 未指定時は現在から7日前の0時がデフォルト値となります。 (optional)
     * @param  string $before 指定日時以前の受注から検索 (optional)
     * @param  string $make_date_min &#x60;after&#x60;と同義 (optional)
     * @param  string $make_date_max &#x60;before&#x60;と同義 (optional)
     * @param  string $update_date_min 指定日時以降に更新された受注から検索 (optional)
     * @param  string $update_date_max 指定日時以前に更新された受注から検索 (optional)
     * @param  string $customer_ids 購入した顧客IDで検索。カンマ区切りにすることで複数検索が可能 (optional)
     * @param  string $customer_name 購入した顧客名で部分一致検索 (optional)
     * @param  string $customer_furigana 購入した顧客フリガナがで部分一致検索 (optional)
     * @param  string $customer_mail 購入した顧客メールアドレスで部分一致検索 (optional)
     * @param  string $accepted_mail_state 受注メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $paid_mail_state 入金メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $delivered_mail_state 配送メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  bool $mobile &#x60;true&#x60;なら携帯からの受注のみ取得 (optional)
     * @param  bool $paid &#x60;true&#x60;なら入金済みの受注のみ取得 (optional)
     * @param  bool $delivered &#x60;true&#x60;なら配送済みの受注のみ取得 (optional)
     * @param  bool $canceled &#x60;true&#x60;ならキャンセル済みの受注のみ取得 (optional)
     * @param  string $payment_ids 使用された決済のIDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $fields レスポンスJSONのキーをカンマ区切りで指定 (optional)
     * @param  int $limit レスポンスの件数を指定。指定がない場合は10。最大100 (optional)
     * @param  int $offset 指定した数値+1件目以降のデータを返す (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getSalesAsyncWithHttpInfo($ids = null, $after = null, $before = null, $make_date_min = null, $make_date_max = null, $update_date_min = null, $update_date_max = null, $customer_ids = null, $customer_name = null, $customer_furigana = null, $customer_mail = null, $accepted_mail_state = null, $paid_mail_state = null, $delivered_mail_state = null, $mobile = null, $paid = null, $delivered = null, $canceled = null, $payment_ids = null, $fields = null, $limit = null, $offset = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2001';
        $request = $this->getSalesRequest($ids, $after, $before, $make_date_min, $make_date_max, $update_date_min, $update_date_max, $customer_ids, $customer_name, $customer_furigana, $customer_mail, $accepted_mail_state, $paid_mail_state, $delivered_mail_state, $mobile, $paid, $delivered, $canceled, $payment_ids, $fields, $limit, $offset);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getSales'
     *
     * @param  string $ids 受注IDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $after 指定日時以降の受注から検索。  &#x60;after&#x60; 未指定時は &#x60;before&#x60; の指定日時の7日前の0時、  &#x60;before&#x60; 未指定時は現在から7日前の0時がデフォルト値となります。 (optional)
     * @param  string $before 指定日時以前の受注から検索 (optional)
     * @param  string $make_date_min &#x60;after&#x60;と同義 (optional)
     * @param  string $make_date_max &#x60;before&#x60;と同義 (optional)
     * @param  string $update_date_min 指定日時以降に更新された受注から検索 (optional)
     * @param  string $update_date_max 指定日時以前に更新された受注から検索 (optional)
     * @param  string $customer_ids 購入した顧客IDで検索。カンマ区切りにすることで複数検索が可能 (optional)
     * @param  string $customer_name 購入した顧客名で部分一致検索 (optional)
     * @param  string $customer_furigana 購入した顧客フリガナがで部分一致検索 (optional)
     * @param  string $customer_mail 購入した顧客メールアドレスで部分一致検索 (optional)
     * @param  string $accepted_mail_state 受注メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $paid_mail_state 入金メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  string $delivered_mail_state 配送メールの送信状態で検索  - &#x60;not_yet&#x60;: 未送信 - &#x60;sent&#x60;: 送信済み - &#x60;pass&#x60;: 送信しない (optional)
     * @param  bool $mobile &#x60;true&#x60;なら携帯からの受注のみ取得 (optional)
     * @param  bool $paid &#x60;true&#x60;なら入金済みの受注のみ取得 (optional)
     * @param  bool $delivered &#x60;true&#x60;なら配送済みの受注のみ取得 (optional)
     * @param  bool $canceled &#x60;true&#x60;ならキャンセル済みの受注のみ取得 (optional)
     * @param  string $payment_ids 使用された決済のIDで検索。カンマ区切りで複数指定可能 (optional)
     * @param  string $fields レスポンスJSONのキーをカンマ区切りで指定 (optional)
     * @param  int $limit レスポンスの件数を指定。指定がない場合は10。最大100 (optional)
     * @param  int $offset 指定した数値+1件目以降のデータを返す (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getSalesRequest($ids = null, $after = null, $before = null, $make_date_min = null, $make_date_max = null, $update_date_min = null, $update_date_max = null, $customer_ids = null, $customer_name = null, $customer_furigana = null, $customer_mail = null, $accepted_mail_state = null, $paid_mail_state = null, $delivered_mail_state = null, $mobile = null, $paid = null, $delivered = null, $canceled = null, $payment_ids = null, $fields = null, $limit = null, $offset = null)
    {

        $resourcePath = '/v1/sales';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($ids !== null) {
            $queryParams['ids'] = ObjectSerializer::toQueryValue($ids, null);
        }
        // query params
        if ($after !== null) {
            $queryParams['after'] = ObjectSerializer::toQueryValue($after, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($before !== null) {
            $queryParams['before'] = ObjectSerializer::toQueryValue($before, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($make_date_min !== null) {
            $queryParams['make_date_min'] = ObjectSerializer::toQueryValue($make_date_min, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($make_date_max !== null) {
            $queryParams['make_date_max'] = ObjectSerializer::toQueryValue($make_date_max, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($update_date_min !== null) {
            $queryParams['update_date_min'] = ObjectSerializer::toQueryValue($update_date_min, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($update_date_max !== null) {
            $queryParams['update_date_max'] = ObjectSerializer::toQueryValue($update_date_max, 'YYYY-MM-DD | YYYY-MM-DD hh:mm:ss');
        }
        // query params
        if ($customer_ids !== null) {
            $queryParams['customer_ids'] = ObjectSerializer::toQueryValue($customer_ids, null);
        }
        // query params
        if ($customer_name !== null) {
            $queryParams['customer_name'] = ObjectSerializer::toQueryValue($customer_name, null);
        }
        // query params
        if ($customer_furigana !== null) {
            $queryParams['customer_furigana'] = ObjectSerializer::toQueryValue($customer_furigana, null);
        }
        // query params
        if ($customer_mail !== null) {
            $queryParams['customer_mail'] = ObjectSerializer::toQueryValue($customer_mail, null);
        }
        // query params
        if ($accepted_mail_state !== null) {
            $queryParams['accepted_mail_state'] = ObjectSerializer::toQueryValue($accepted_mail_state, null);
        }
        // query params
        if ($paid_mail_state !== null) {
            $queryParams['paid_mail_state'] = ObjectSerializer::toQueryValue($paid_mail_state, null);
        }
        // query params
        if ($delivered_mail_state !== null) {
            $queryParams['delivered_mail_state'] = ObjectSerializer::toQueryValue($delivered_mail_state, null);
        }
        // query params
        if ($mobile !== null) {
            $queryParams['mobile'] = ObjectSerializer::toQueryValue($mobile, null);
        }
        // query params
        if ($paid !== null) {
            $queryParams['paid'] = ObjectSerializer::toQueryValue($paid, null);
        }
        // query params
        if ($delivered !== null) {
            $queryParams['delivered'] = ObjectSerializer::toQueryValue($delivered, null);
        }
        // query params
        if ($canceled !== null) {
            $queryParams['canceled'] = ObjectSerializer::toQueryValue($canceled, null);
        }
        // query params
        if ($payment_ids !== null) {
            $queryParams['payment_ids'] = ObjectSerializer::toQueryValue($payment_ids, null);
        }
        // query params
        if ($fields !== null) {
            $queryParams['fields'] = ObjectSerializer::toQueryValue($fields, null);
        }
        // query params
        if ($limit !== null) {
            $queryParams['limit'] = ObjectSerializer::toQueryValue($limit, null);
        }
        // query params
        if ($offset !== null) {
            $queryParams['offset'] = ObjectSerializer::toQueryValue($offset, null);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation sendSalesMail
     *
     * メールの送信
     *
     * @param  int $sale_id sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdMailsBody $body body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return void
     */
    public function sendSalesMail($sale_id, $body = null)
    {
        $this->sendSalesMailWithHttpInfo($sale_id, $body);
    }

    /**
     * Operation sendSalesMailWithHttpInfo
     *
     * メールの送信
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdMailsBody $body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function sendSalesMailWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '';
        $request = $this->sendSalesMailRequest($sale_id, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            return [null, $statusCode, $response->getHeaders()];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
            }
            throw $e;
        }
    }

    /**
     * Operation sendSalesMailAsync
     *
     * メールの送信
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdMailsBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendSalesMailAsync($sale_id, $body = null)
    {
        return $this->sendSalesMailAsyncWithHttpInfo($sale_id, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation sendSalesMailAsyncWithHttpInfo
     *
     * メールの送信
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdMailsBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function sendSalesMailAsyncWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '';
        $request = $this->sendSalesMailRequest($sale_id, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'sendSalesMail'
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SaleIdMailsBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function sendSalesMailRequest($sale_id, $body = null)
    {
        // verify the required parameter 'sale_id' is set
        if ($sale_id === null || (is_array($sale_id) && count($sale_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $sale_id when calling sendSalesMail'
            );
        }

        $resourcePath = '/v1/sales/{sale_id}/mails';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($sale_id !== null) {
            $resourcePath = str_replace(
                '{' . 'sale_id' . '}',
                ObjectSerializer::toPathValue($sale_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                []
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                [],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation statSale
     *
     * 売上集計の取得
     *
     * @param  string $make_date 集計対象とする売上の作成日。形式は\&quot;2017-04-12\&quot;、\&quot;2017/04/12\&quot;など。指定しない場合は今日の日付が使われる (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2002
     */
    public function statSale($make_date = null)
    {
        list($response) = $this->statSaleWithHttpInfo($make_date);
        return $response;
    }

    /**
     * Operation statSaleWithHttpInfo
     *
     * 売上集計の取得
     *
     * @param  string $make_date 集計対象とする売上の作成日。形式は\&quot;2017-04-12\&quot;、\&quot;2017/04/12\&quot;など。指定しない場合は今日の日付が使われる (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2002, HTTP status code, HTTP response headers (array of strings)
     */
    public function statSaleWithHttpInfo($make_date = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2002';
        $request = $this->statSaleRequest($make_date);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2002',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation statSaleAsync
     *
     * 売上集計の取得
     *
     * @param  string $make_date 集計対象とする売上の作成日。形式は\&quot;2017-04-12\&quot;、\&quot;2017/04/12\&quot;など。指定しない場合は今日の日付が使われる (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function statSaleAsync($make_date = null)
    {
        return $this->statSaleAsyncWithHttpInfo($make_date)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation statSaleAsyncWithHttpInfo
     *
     * 売上集計の取得
     *
     * @param  string $make_date 集計対象とする売上の作成日。形式は\&quot;2017-04-12\&quot;、\&quot;2017/04/12\&quot;など。指定しない場合は今日の日付が使われる (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function statSaleAsyncWithHttpInfo($make_date = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2002';
        $request = $this->statSaleRequest($make_date);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'statSale'
     *
     * @param  string $make_date 集計対象とする売上の作成日。形式は\&quot;2017-04-12\&quot;、\&quot;2017/04/12\&quot;など。指定しない場合は今日の日付が使われる (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function statSaleRequest($make_date = null)
    {

        $resourcePath = '/v1/sales/stat';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($make_date !== null) {
            $queryParams['make_date'] = ObjectSerializer::toQueryValue($make_date, null);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateSale
     *
     * 受注データの更新
     *
     * @param  int $sale_id sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SalesSaleIdBody $body body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \ColorMeShop\Swagger\Model\InlineResponse2004
     */
    public function updateSale($sale_id, $body = null)
    {
        list($response) = $this->updateSaleWithHttpInfo($sale_id, $body);
        return $response;
    }

    /**
     * Operation updateSaleWithHttpInfo
     *
     * 受注データの更新
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SalesSaleIdBody $body (optional)
     *
     * @throws \ColorMeShop\Swagger\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \ColorMeShop\Swagger\Model\InlineResponse2004, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateSaleWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2004';
        $request = $this->updateSaleRequest($sale_id, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\ColorMeShop\Swagger\Model\InlineResponse2004',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateSaleAsync
     *
     * 受注データの更新
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SalesSaleIdBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateSaleAsync($sale_id, $body = null)
    {
        return $this->updateSaleAsyncWithHttpInfo($sale_id, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateSaleAsyncWithHttpInfo
     *
     * 受注データの更新
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SalesSaleIdBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateSaleAsyncWithHttpInfo($sale_id, $body = null)
    {
        $returnType = '\ColorMeShop\Swagger\Model\InlineResponse2004';
        $request = $this->updateSaleRequest($sale_id, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'updateSale'
     *
     * @param  int $sale_id (required)
     * @param  \ColorMeShop\Swagger\Model\SalesSaleIdBody $body (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function updateSaleRequest($sale_id, $body = null)
    {
        // verify the required parameter 'sale_id' is set
        if ($sale_id === null || (is_array($sale_id) && count($sale_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $sale_id when calling updateSale'
            );
        }

        $resourcePath = '/v1/sales/{sale_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($sale_id !== null) {
            $resourcePath = str_replace(
                '{' . 'sale_id' . '}',
                ObjectSerializer::toPathValue($sale_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'PUT',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
