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

import com.smyhub.store.mengyastorebackendjava.config.AppProperties;
import com.smyhub.store.mengyastorebackendjava.dto.request.AdminVerifyRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

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

    private final AppProperties appProperties;

    /**
     * Matches Go backend: top-level {@code {"valid": true/false}} (frontend reads {@code response.data.valid} from axios).
     */
    @PostMapping("/verify")
    public ResponseEntity<Map<String, Boolean>> verify(@RequestBody(required = false) AdminVerifyRequest req) {
        if (req == null || !StringUtils.hasText(req.getToken())) {
            return ResponseEntity.ok(Map.of("valid", false));
        }
        boolean valid = req.getToken().equals(appProperties.getAdminToken());
        return ResponseEntity.ok(Map.of("valid", valid));
    }
}
