package com.auth.service.base.controller;

import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;
import com.auth.model.base.dto.EmailConfigDto;
import com.auth.model.base.vo.EmailConfigVo;
import com.auth.dao.base.entity.EmailConfigEntity;
import com.auth.service.base.service.EmailConfigService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统邮件服务器配置 前端控制器
 * </p>
 *
 * @author AuthoritySystem
 * @since 2025-07-17 23:06:38
 */
@Tag(name = "系统邮件服务器配置", description = "系统邮件服务器配置相关接口")
@RestController
@RequestMapping("/api/v1/base/email-config")
@RequiredArgsConstructor
public class EmailConfigController {

    private final EmailConfigService emailConfigService;

    @Operation(summary = "分页查询系统邮件服务器配置", description = "分页查询系统邮件服务器配置")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<EmailConfigVo>> getEmailConfigPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            EmailConfigDto dto) {
        Page<EmailConfigEntity> pageParams = new Page<>(page, limit);
        PageResult<EmailConfigVo> pageResult = emailConfigService.getEmailConfigPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询系统邮件服务器配置详情", description = "根据id查询系统邮件服务器配置详情")
    @GetMapping("{id}")
    public Result<EmailConfigVo> getEmailConfigById(@PathVariable("id") Long id) {
        EmailConfigVo emailConfigVo = emailConfigService.getEmailConfigById(id);

        return Result.success(emailConfigVo);
    }

    @Operation(summary = "添加系统邮件服务器配置", description = "添加系统邮件服务器配置")
    @PostMapping()
    public Result<String> addEmailConfig(@Valid @RequestBody EmailConfigDto dto) {
        emailConfigService.addEmailConfig(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新系统邮件服务器配置", description = "更新系统邮件服务器配置")
    @PutMapping()
    public Result<String> updateEmailConfig(@Valid @RequestBody EmailConfigDto dto) {
        emailConfigService.updateEmailConfig(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除系统邮件服务器配置", description = "删除系统邮件服务器配置")
    @DeleteMapping()
    public Result<String> deleteEmailConfig(@RequestBody List<Long> ids) {
        emailConfigService.deleteEmailConfig(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}