package com.xueyi.system.staff.controller;

import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.common.security.annotation.RequiresPermissions;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.system.staff.domain.dto.DmVisitorSmsConfigDto;
import com.xueyi.system.staff.domain.query.DmVisitorSmsConfigQuery;
import com.xueyi.system.staff.service.IDmVisitorSmsConfigService;
import com.xueyi.system.staff.service.impl.DmVisitorSmsConfigServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

/**
 * 租户访客接待短信模板配置管理 业务处理
 *
 * @author xueyi
 */
@RestController
@RequestMapping("/visitor/sms")
public class DmVisitorSmsConfigController extends BaseController<DmVisitorSmsConfigQuery, DmVisitorSmsConfigDto, IDmVisitorSmsConfigService> {

    @Autowired
    private DmVisitorSmsConfigServiceImpl visitorSmsConfigService;

    /** 定义节点名称 */
    @Override
    protected String getNodeName() {
        return "租户访客接待短信模板配置" ;
    }

    /**
     * 查询租户访客接待短信模板配置列表
     */
    @Override
    @GetMapping("/list")
    @RequiresPermissions(Auth.DM_VISITOR_SMS_CONFIG_LIST)
    public AjaxResult list(DmVisitorSmsConfigQuery visitorSmsConfig) {
        return super.list(visitorSmsConfig);
    }

    /**
     * 查询租户访客接待短信模板配置详细
     */
    @Override
    @GetMapping(value = "/{id}")
    @RequiresPermissions(Auth.DM_VISITOR_SMS_CONFIG_SINGLE)
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    /**
     * 租户访客接待短信模板配置新增
     */
    @Override
    @PostMapping
    @RequiresPermissions(Auth.DM_VISITOR_SMS_CONFIG_ADD)
    @Log(title = "租户访客接待短信模板配置管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated({V_A.class}) @RequestBody DmVisitorSmsConfigDto visitorSmsConfig) {
        if (visitorSmsConfig.getId()!= null) {//
            DmVisitorSmsConfigDto dto = visitorSmsConfigService.selectById(visitorSmsConfig.getId());
            dto.setCompanyAddress(visitorSmsConfig.getCompanyAddress());
            dto.setCompanyName(visitorSmsConfig.getCompanyName());
            dto.setParkPrompt(visitorSmsConfig.getParkPrompt());
            visitorSmsConfigService.update(dto);
            return success();
        } else {
            return super.add(visitorSmsConfig);
        }
    }

    /**
     * 租户访客接待短信模板配置修改
     */
    @Override
    @PutMapping
    @RequiresPermissions(Auth.DM_VISITOR_SMS_CONFIG_EDIT)
    @Log(title = "租户访客接待短信模板配置管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody DmVisitorSmsConfigDto visitorSmsConfig) {
        return super.edit(visitorSmsConfig);
    }

    /**
     * 租户访客接待短信模板配置批量删除
     */
    @Override
    @DeleteMapping("/batch/{idList}")
    @RequiresPermissions(Auth.DM_VISITOR_SMS_CONFIG_DEL)
    @Log(title = "租户访客接待短信模板配置管理", businessType = BusinessType.DELETE)
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }

    /**
     * 获取租户访客接待短信模板配置选择框列表
     */
    @Override
    @GetMapping("/option")
    public AjaxResult option() {
        return super.option();
    }

    interface Auth {
        /** 系统 - 租户访客接待短信模板配置管理 - 列表 */
        String DM_VISITOR_SMS_CONFIG_LIST = "visitor:visitor/sms:list";
        /** 系统 - 租户访客接待短信模板配置管理 - 新增 */
        String DM_VISITOR_SMS_CONFIG_ADD = "visitor:visitor/sms:add";
        /** 系统 - 租户访客接待短信模板配置管理 - 详情 */
        String DM_VISITOR_SMS_CONFIG_SINGLE = "visitor:visitor/sms:single";

        /** 系统 - 租户访客接待短信模板配置管理 - 修改 */
        String DM_VISITOR_SMS_CONFIG_EDIT = "visitor:visitor/sms:edit";
        /** 系统 - 租户访客接待短信模板配置管理 - 删除 */
        String DM_VISITOR_SMS_CONFIG_DEL = "visitor:visitor/sms:delete";
    }
}
