package com.smyhub.store.mengyastorebackendjava.controller.admin;

import com.smyhub.store.mengyastorebackendjava.dto.request.MaintenanceRequest;
import com.smyhub.store.mengyastorebackendjava.dto.request.SmtpConfigRequest;
import com.smyhub.store.mengyastorebackendjava.dto.response.ApiResponse;
import com.smyhub.store.mengyastorebackendjava.dto.response.MaintenanceResponse;
import com.smyhub.store.mengyastorebackendjava.dto.response.SmtpConfigResponse;
import com.smyhub.store.mengyastorebackendjava.service.SiteService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/site")
@RequiredArgsConstructor
public class AdminSiteController {

    private final SiteService siteService;

    @PostMapping("/maintenance")
    public ResponseEntity<ApiResponse<MaintenanceResponse>> setMaintenance(
            @RequestBody MaintenanceRequest req) {
        siteService.setMaintenance(req.isEnabled(), req.getReason());
        return ResponseEntity.ok(ApiResponse.ok(siteService.getMaintenance()));
    }

    @GetMapping("/smtp")
    public ResponseEntity<ApiResponse<SmtpConfigResponse>> getSmtp() {
        return ResponseEntity.ok(ApiResponse.ok(siteService.getSmtpConfigResponse(true)));
    }

    @PostMapping("/smtp")
    public ResponseEntity<ApiResponse<SmtpConfigResponse>> setSmtp(
            @RequestBody SmtpConfigRequest req) {
        siteService.setSmtpConfig(req);
        return ResponseEntity.ok(ApiResponse.ok(siteService.getSmtpConfigResponse(true)));
    }
}
