package com.ffii.fpsms.modules.common.mail.web

import com.ffii.fpsms.modules.common.mail.entity.MailTemplate
import com.ffii.fpsms.modules.common.mail.service.MailReminderService
import com.ffii.fpsms.modules.common.mail.service.MailService
import com.ffii.fpsms.modules.common.mail.service.MailTemplateService
import com.ffii.fpsms.modules.common.mail.web.models.MailSaveRequest
import com.ffii.fpsms.modules.common.mail.web.models.Setting
import com.ffii.fpsms.modules.settings.entity.Settings
import com.ffii.fpsms.modules.settings.service.SettingsService
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*
import java.time.LocalDateTime
import java.util.Date

@RestController
@RequestMapping("/mails")
class MailController(
    private val settingsService: SettingsService,
    private val mailService: MailService,
    private val mailReminderService: MailReminderService
) {
    @GetMapping("/setting")
    fun mailSetting(): List<Settings> {
        return settingsService.findAllByCategory("MAIL")
    }

    @GetMapping("/test-send")
    fun mailTestSend() {
        mailReminderService.createEmailRequest(LocalDateTime.now().toString(), listOf("jason.tom@2fi-solutions.com.hk"))
    }

    @PostMapping("/save")
    fun saveMail(@Valid @RequestBody mailSave: MailSaveRequest): List<Settings> {
        return mailService.saveMail(mailSave)
    }
}