package com.xhpc.user.controller;

import com.xhpc.common.api.dto.XhpcChargingStationDto;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.security.service.TokenService;
import com.xhpc.system.api.model.LoginUser;
import com.xhpc.user.domain.AuthSetToken;
import com.xhpc.user.service.IAuthSetTokenService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/authSetToken")
public class AuthSetTokenController  extends BaseController {

    @Resource
    private IAuthSetTokenService authSetTokenService;
    @Resource
    private TokenService tokenService;

    @GetMapping("/getList")
    public TableDataInfo getList(String name) {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser();
        String tenantId = loginUser.getTenantId();
        List<Map<String, Object>> list = authSetTokenService.getList(name, tenantId);
        return getDataTable(list);
    }

    @GetMapping("/getById")
    public R getById(@RequestParam("id")Long id){
        return R.ok(authSetTokenService.getById(id));
    }

    @PostMapping(value = "/insertAuthSetToken")
    public R insertAuthSetToken(@RequestBody AuthSetToken authSetToken) {
        LoginUser loginUser = tokenService.getLoginUser();
        String tenantId = loginUser.getTenantId();
        authSetToken.setTenantId(tenantId);
        authSetTokenService.insertAuthSetToken(authSetToken);
        return R.ok(null,"操作成功");
    }

    @PostMapping(value = "/updateAuthSetToken")
    public R updateAuthSetToken(@RequestBody AuthSetToken authSetToken) {
        LoginUser loginUser = tokenService.getLoginUser();
        String tenantId = loginUser.getTenantId();
        authSetToken.setTenantId(tenantId);
        authSetTokenService.updateAuthSetToken(authSetToken);
        return R.ok();
    }

}
