package com.community.huiju.controller;

import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.service.ITaUserLicenseOrderService;
import com.community.huiju.service.ITaUserLicenseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "用户车牌操作的API",description = "用户车牌操作的API")
public class UserLicenseController extends BaseController {

    @Autowired
    private ITaUserLicenseService iTaUserLicenseService;

    @Autowired
    private ITaUserLicenseOrderService iTaUserLicenseOrderService;

    @ApiOperation(value = "关联车牌", notes = "关联车牌")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "carNo", value = "车牌号"),
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    @RequestMapping(value = "/license/associated/{carNo}", method = RequestMethod.POST)
    public ResponseBean associatedLicense(@PathVariable("carNo") String carNo, HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTaUserLicenseService.associatedLicense(userElement, carNo);
        return responseBean;
    }

    @ApiOperation(value = "用户所有车牌", notes = "用户所有车牌")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token")
    })
    @RequestMapping(value = "/license/user/all", method = RequestMethod.GET)
    public ResponseBean getAllUserLicense(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTaUserLicenseService.getAllUserLicense(userElement);

        return responseBean;
    }

    @ApiOperation(value = "用户删除车牌", notes = "用户删除车牌")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token"),
            @ApiImplicitParam(paramType = "path", dataTypeClass = Integer.class, name = "id", value = "车牌id")
    })
    @RequestMapping(value = "/license/user/{id}", method = RequestMethod.DELETE)
    public ResponseBean deleteUserLicense(@PathVariable("id") Integer id,HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTaUserLicenseService.deleteUserLicense(userElement, id);

        return responseBean;
    }

    @ApiOperation(value = "用户车辆缴费列表", notes = "用户车辆缴费列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "token"),
    })
    @RequestMapping(value = "/license/user/order", method = RequestMethod.GET)
    public ResponseBean userLicenseOrder(HttpSession session) {
        ResponseBean responseBean = new ResponseBean();
        UserElement userElement = getUserElement(session);
        responseBean = iTaUserLicenseOrderService.selectRecords(userElement);
        return responseBean;
    }



}
