package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysPhoneBo;
import org.dromara.system.domain.vo.SysPhoneVo;
import org.dromara.system.service.ISysPhoneService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 联系电话管理
 *
 * @author Antigravity
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/phone")
public class SysPhoneController extends BaseController {

    private final ISysPhoneService sysPhoneService;

    /**
     * 根据ID获取联系电话
     */
    @SaIgnore
    @GetMapping("/{id}")
    public R<SysPhoneVo> getInfo(@NotNull(message = "ID不能为空")
                                 @PathVariable Long id) {
        return R.ok(sysPhoneService.queryById(id));
    }

    /**
     * 修改联系电话
     */
    @Log(title = "联系电话管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysPhoneBo bo) {
        sysPhoneService.updateByBo(bo);
        return R.ok();
    }

}
