<?php

namespace app\common\controller;

use app\BaseController;
use app\common\middleware\Auth;
use app\common\api\BatchApi;
use app\common\state\ProjectState;

/**
 * Description of Batch
 *
 * @author sgq
 */
class Batch extends BaseController {

    protected $middleware = [Auth::class];

    public function checkBatchValid() {
        $user = session("user");
        if ($this->request["id"] && $this->request["type"]) {
            $params = [];
            switch ($this->request["type"]) {
                case ProjectState::HOUSE:
                    $info = \app\common\api\HouseApi::getInfoById($this->request["id"]);
                    $params = ["type" => $this->request["type"], "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]];
                    break;
            }
            return json(BatchApi::checkBatchValid($params, $user["type"]));
        }
        return json(BatchApi::checkBatchValid($this->request->param(), $user["type"]));
    }

    public function listBatchByType() {
        $projectType = $this->request["type"];
        $talentType = $this->request["source"];
        return json(BatchApi::getValidBatchs($projectType, $talentType));
    }

}
