package com.liquidnet.client.admin.web.controller.zhengzai.adam;

import com.liquidnet.client.admin.common.annotation.Log;
import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.core.page.TableDataInfo;
import com.liquidnet.client.admin.common.enums.BusinessType;
import com.liquidnet.client.admin.zhengzai.adam.service.IAdamCaomeiPassportAdminService;
import com.liquidnet.service.adam.dto.param.AdamCaomeiPassportSearchParam;
import com.liquidnet.service.adam.dto.vo.AdamCaomeiPassportDetailVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Api(tags = "草莓护照-护照管理")
@Controller
@RequestMapping("adam/caomei/passport")
public class AdamCaomeiPassportController extends BaseController {

    private final String prefix = "zhengzai/adam/caomei/passport";

    @Autowired
    private IAdamCaomeiPassportAdminService adamCaomeiPassportAdminService;

    @RequiresPermissions("adam:caomei:passport:list")
    @GetMapping()
    public String view() {
        return prefix + "/passport_list";
    }

    @RequiresPermissions("adam:caomei:passport:list")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(AdamCaomeiPassportSearchParam param) {
        startPage();
        PageInfo<?> pageInfo = adamCaomeiPassportAdminService.listPassports(param);
        return getDataTable(pageInfo);
    }

    @RequiresPermissions("adam:caomei:passport:list")
    @GetMapping("detail/{passportNo}")
    public String detail(@PathVariable("passportNo") String passportNo, ModelMap mmap) {
        AdamCaomeiPassportDetailVo detail = adamCaomeiPassportAdminService.getPassportDetail(passportNo);
        mmap.put("detail", detail);
        return prefix + "/passport_detail";
    }

    @RequiresPermissions("adam:caomei:passport:edit")
    @Log(title = "草莓护照-护照解绑", businessType = BusinessType.UPDATE)
    @PostMapping("unbind")
    @ResponseBody
    public AjaxResult unbind(@RequestParam("passportNo") String passportNo) {
        boolean ok = adamCaomeiPassportAdminService.unbindPassport(passportNo);
        if (!ok) {
            return error("解绑失败：护照不存在或当前未绑定用户");
        }
        return success();
    }
}
