package com.wgb.system.service.controller;

import com.alibaba.fastjson.JSON;
import com.data.model.restful.response.InternalResponse;
import com.wgb.system.service.domain.model.User;
import com.wgb.system.service.domain.model.UserEnterprise;
import com.wgb.system.service.domain.request.UserEnterpriseList;
import com.wgb.system.service.domain.request.UserList;
import com.wgb.system.service.domain.response.LayuiTableResponse;
import com.wgb.system.service.domain.response.VerificationOfLicenceResponse;
import com.wgb.system.service.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation(value = "/获取维修单列表", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/getList",method = {RequestMethod.POST})
    public LayuiTableResponse getList(@RequestBody UserList userList){
        log.info("Start to execute /user/getList with, Param", userList);
        LayuiTableResponse response= userService.getList(userList);
        log.info("Return object for /user/getList is result={}", JSON.toJSON(response));
        return response;
    }


    @ApiOperation(value = "/上传用户信息", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/uploadUserFile",method = RequestMethod.POST)
    public InternalResponse uploadUserFile(@RequestParam("file") MultipartFile file)throws Exception{
        if (file.isEmpty()) {
            return InternalResponse.fail();
        }
        userService.uploadUserFile(file);
        return InternalResponse.success();
    }

    @ApiOperation(value = "/下载用户信息", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/downloadUserFileTemplate",method = {RequestMethod.POST})
    public InternalResponse downloadUserFileTemplate(){
        return InternalResponse.success();
    }


    @ApiOperation(value = "/验证是否审核企业信息", response = VerificationOfLicenceResponse.class)
    @RequestMapping(value = "/verificationOfLicence",method = RequestMethod.GET)
    @ResponseBody
    public InternalResponse verificationOfLicence(String userNo){
        log.info("Start to execute /access/register with, param={}", userNo);
        VerificationOfLicenceResponse response= userService.verificationOfLicence(userNo);
        log.info("Return object for /businessCategory/saveOrUpdate is result={}", response);
        return InternalResponse.success().withBody(response);
    }

    @ApiOperation(value = "/提交审核证件状态", response = User.class)
    @RequestMapping(value = "/saveLicence",method = {RequestMethod.GET})
    @ResponseBody
    public InternalResponse saveLicence(
        @ModelAttribute UserEnterprise userEnterprise, @RequestPart(value="file", required = true) final MultipartFile file)throws Exception{
        log.info("Start to execute /access/register with, param={}", JSON.toJSON(userEnterprise));
        userService.saveLicence(userEnterprise,file);
        log.info("Return object for /businessCategory/saveOrUpdate is result={}", "success");
        return InternalResponse.success();
    }


    @ApiOperation(value = "/获取维修单列表", response = LayuiTableResponse.class)
    @ResponseBody
    @RequestMapping(value = "/userEnterpriseList",method = {RequestMethod.POST})
    public LayuiTableResponse userEnterpriseList(@RequestBody UserEnterpriseList request){
        log.info("Start to execute /user/getList with, Param", request);
        LayuiTableResponse response= userService.userEnterpriseList(request);
        log.info("Return object for /user/getList is result={}", JSON.toJSON(response));
        return response;
    }
}
