package org.xyzh.crontab.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.crontab.EmailDefaultService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.crontab.TbCrontabEmailDefault;

/**
 * @description 定时任务邮件通知默认接收人控制器
 * @filename EmailDefaultController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-11-18
 */
@RestController
@RequestMapping("/crontab/email/default")
public class EmailDefaultController {

    private static final Logger logger = LoggerFactory.getLogger(EmailDefaultController.class);

    @Autowired
    private EmailDefaultService emailDefaultService;

    /**
     * @description 创建默认接收人
     * @param emailDefault 默认接收人
     * @return ResultDomain<TbCrontabEmailDefault>
     */
    @PostMapping
    public ResultDomain<TbCrontabEmailDefault> createDefault(@RequestBody TbCrontabEmailDefault emailDefault) {
        return emailDefaultService.createDefault(emailDefault);
    }

    /**
     * @description 更新默认接收人
     * @param emailDefault 默认接收人
     * @return ResultDomain<TbCrontabEmailDefault>
     */
    @PutMapping
    public ResultDomain<TbCrontabEmailDefault> updateDefault(@RequestBody TbCrontabEmailDefault emailDefault) {
        return emailDefaultService.updateDefault(emailDefault);
    }

    /**
     * @description 删除默认接收人
     * @param defaultId 默认ID
     * @return ResultDomain<Boolean>
     */
    @DeleteMapping("/{defaultId}")
    public ResultDomain<Boolean> deleteDefault(@PathVariable String defaultId) {
        return emailDefaultService.deleteDefault(defaultId);
    }

    /**
     * @description 根据defaultId查询
     * @param defaultId 默认ID
     * @return ResultDomain<TbCrontabEmailDefault>
     */
    @GetMapping("/{defaultId}")
    public ResultDomain<TbCrontabEmailDefault> getDefaultById(@PathVariable String defaultId) {
        return emailDefaultService.getDefaultById(defaultId);
    }

    /**
     * @description 根据metaId查询
     * @param metaId 元数据ID
     * @return ResultDomain<TbCrontabEmailDefault>
     */
    @GetMapping("/meta/{metaId}")
    public ResultDomain<TbCrontabEmailDefault> getDefaultByMetaId(@PathVariable String metaId) {
        return emailDefaultService.getDefaultByMetaId(metaId);
    }
}
