package com.example.backend.controller;

import com.example.backend.common.ApiResponse;
import com.example.backend.dto.DingtalkUserInfo;
import com.example.backend.service.DingtalkService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api")
@Validated
public class DingtalkController {
    private final DingtalkService dingtalkService;
    
    public DingtalkController(DingtalkService dingtalkService) {
        this.dingtalkService = dingtalkService;
    }


    @GetMapping("/getUserInfo")
    public ApiResponse<DingtalkUserInfo> getUserInfo(
            @RequestParam @NotBlank String code,
            @RequestParam @NotBlank String corpId) {
        DingtalkUserInfo userInfo = dingtalkService.getUserInfo(code, corpId);
        return ApiResponse.ok(userInfo);
    }

    /**
     * 文件上传接口
     * @return
     */
    @PostMapping("/commit-file")
    public boolean commitFile(
            @RequestParam @NotBlank String userId) {
        return dingtalkService.commitFile(userId);
    }
} 