package com.hhh.cloud.framework.example.client.controller;

import com.alibaba.fastjson.JSONObject;
import com.hhh.cloud.framework.example.client.entity.SysClient;
import com.hhh.cloud.framework.megrez.starter.auth.service.ITokenService;
import com.hhh.cloud.framework.util.enumeration.CodeEnum;
import com.hhh.cloud.framework.util.exception.BusinessException;
import com.hhh.cloud.framework.util.result.Result;
import com.hhh.cloud.framework.util.result.TableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private ITokenService iTokenService;

    @GetMapping("agentToken")
    public String agentToken() {
        return iTokenService.getAgentToken();
    }

    @PostMapping("/errorTs")
    public Result errorTs() {
        throw new BusinessException("测试错误");
    }

    @PostMapping("/dataOsSuccess")
    public Result dataOsSuccess(@RequestBody JSONObject jsonObject) {
        jsonObject.put("re", "13527821562");
        return new Result(CodeEnum.SUCCESS.get(), jsonObject, "测试成功");
    }

    @PostMapping("/dataOsError")
    public Result dataOsError(@RequestBody JSONObject jsonObject) {
        jsonObject.put("re", "13527821562");
        return new Result(CodeEnum.BUSINESS_ERROR.get(), jsonObject, "测试失败");
    }

    @PostMapping("/dataForm")
    public Result dataForm(SysClient client) {
        return new Result(CodeEnum.SUCCESS.get(), client, "");
    }

    @GetMapping("/bl")
    public boolean bl(int i, int c) {
        return true;
    }

    @PostMapping("/table")
    public TableResult table(@RequestBody JSONObject jsonObject) {
        List<JSONObject> list = new ArrayList<>();
        JSONObject data = new JSONObject();
        data.put("date", "2016-05-02");
        data.put("name", "王小虎");
        data.put("address", "上海市普陀区金沙江路 1518 弄");
        JSONObject data1 = new JSONObject();
        data1.put("date", "2016-05-02");
        data1.put("name", "王小虎");
        data1.put("address", "上海市普陀区金沙江路 1518 弄");
        JSONObject data2 = new JSONObject();
        data2.put("date", "2016-05-02");
        data2.put("name", "王小虎");
        data2.put("address", "上海市普陀区金沙江路 1518 弄");
        JSONObject data3 = new JSONObject();
        data3.put("date", "2016-05-02");
        data3.put("name", "王小虎");
        data3.put("address", "上海市普陀区金沙江路 1518 弄");
        JSONObject data4 = new JSONObject();
        data4.put("date", "2016-05-02");
        data4.put("name", "王小虎");
        data4.put("address", "上海市普陀区金沙江路 1518 弄");
        list.add(data);
        list.add(data1);
        list.add(data2);
        list.add(data3);
        list.add(data4);
        return new TableResult(CodeEnum.SUCCESS.get(), list, 15, "");
    }
}
