package com.fuint.module.backendApi.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.ext.CountryDto;
import com.fuint.common.util.AuthUserUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.common.Constants;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.CountryService;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtCountry;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 国家表管理类controller
 *
 * Created by pzg
 * CopyRight https://www.fuint.cn
 */
@Api(tags="管理端-国家表相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/country")
public class BackendCountryController extends BaseController {

    /**
     * 国家表服务接口
     */
    private CountryService countryService;

    /**
     * 国家表列表查询
     *
     * @param  request HttpServletRequest对象
     * @return 国家表列表
     */
    @ApiOperation(value = "国家表列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('country:list')")
    public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
        return getSuccessResult(null);
    }

    /**
     * 更新国家表状态
     *
     * @return
     */
    @ApiOperation(value = "更新国家表状态")
    @RequestMapping(value = "/updateCountry", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('country:edit')")
    public ResponseObject updateCountry(CountryDto countryDto) throws BusinessCheckException {
        AccountInfo accountInfo = AuthUserUtil.get();
        if (accountInfo == null) {
            return getFailureResult(1001, "请先登录");
        }
        Long accountInfoId = accountInfo.getId();
        boolean result = countryService.updateCountry(countryDto,accountInfoId);
        return result ?getSuccessResult(true):getFailureResult(1002,"更新失败");
    }

    /**
     * 保存国家表
     *
     * @return
     */
    @ApiOperation(value = "保存国家表")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('country:add')")
    public ResponseObject saveHandler(@RequestBody CountryDto countryDto) throws BusinessCheckException {
        AccountInfo accountInfo = AuthUserUtil.get();
        if (accountInfo == null) {
            return getFailureResult(1001, "请先登录");
        }
        Long accountInfoId = accountInfo.getId();
        boolean result = countryService.saveCountry(countryDto,accountInfoId);
        return result?getSuccessResult(true):getFailureResult(1002,"保持失败");
    }

    /**
     * 获取国家表详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取国家表详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('country:list')")
    public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {


        return getSuccessResult(null);
    }
}
