package com.lesingle.edu.controller.school;

import com.lesingle.edu.common.annotation.Log;
import com.lesingle.edu.common.enums.LogModule;
import com.lesingle.edu.common.enums.LogOperationType;
import com.lesingle.edu.common.annotation.RequireRole;
import com.lesingle.edu.common.enums.UserRole;
import com.lesingle.edu.common.response.Result;
import com.lesingle.edu.common.security.SecurityUtils;
import com.lesingle.edu.dto.request.BasicSettingsUpdateRequest;
import com.lesingle.edu.dto.request.NotificationSettingsUpdateRequest;
import com.lesingle.edu.dto.request.SchoolSettingsUpdateRequest;
import com.lesingle.edu.dto.request.SecuritySettingsUpdateRequest;
import com.lesingle.edu.dto.response.BasicSettingsResponse;
import com.lesingle.edu.dto.response.NotificationSettingsResponse;
import com.lesingle.edu.dto.response.SchoolSettingsResponse;
import com.lesingle.edu.dto.response.SecuritySettingsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 学校端 - 系统设置
 */
@Tag(name = "学校端 - 系统设置", description = "School Settings APIs")
@RestController
@RequestMapping("/api/v1/school/settings")
@RequiredArgsConstructor
@RequireRole(UserRole.SCHOOL)
public class SchoolSettingsController {

    @GetMapping
    @Operation(summary = "获取系统设置")
    public Result<SchoolSettingsResponse> getSettings() {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现系统设置查询，根据 tenantId 查询
        return Result.success(SchoolSettingsResponse.builder()
                .basic(BasicSettingsResponse.builder().build())
                .notification(NotificationSettingsResponse.builder().build())
                .security(SecuritySettingsResponse.builder().build())
                .build());
    }

    @PutMapping
    @Operation(summary = "更新系统设置")
    @Log(module = LogModule.SYSTEM_SETTING, type = LogOperationType.UPDATE, description = "更新系统设置")
    public Result<SchoolSettingsResponse> updateSettings(@RequestBody SchoolSettingsUpdateRequest request) {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现系统设置更新，根据 tenantId 更新
        return Result.success(SchoolSettingsResponse.builder().build());
    }

    @GetMapping("/basic")
    @Operation(summary = "获取基础设置")
    public Result<BasicSettingsResponse> getBasicSettings() {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现基础设置查询，根据 tenantId 查询
        return Result.success(BasicSettingsResponse.builder().build());
    }

    @PutMapping("/basic")
    @Operation(summary = "更新基础设置")
    @Log(module = LogModule.SYSTEM_SETTING, type = LogOperationType.UPDATE, description = "更新基础设置")
    public Result<BasicSettingsResponse> updateBasicSettings(@RequestBody BasicSettingsUpdateRequest request) {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现基础设置更新，根据 tenantId 更新
        return Result.success(BasicSettingsResponse.builder().build());
    }

    @GetMapping("/notification")
    @Operation(summary = "获取通知设置")
    public Result<NotificationSettingsResponse> getNotificationSettings() {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现通知设置查询，根据 tenantId 查询
        return Result.success(NotificationSettingsResponse.builder().build());
    }

    @PutMapping("/notification")
    @Operation(summary = "更新通知设置")
    @Log(module = LogModule.SYSTEM_SETTING, type = LogOperationType.UPDATE, description = "更新通知设置")
    public Result<NotificationSettingsResponse> updateNotificationSettings(@RequestBody NotificationSettingsUpdateRequest request) {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现通知设置更新，根据 tenantId 更新
        return Result.success(NotificationSettingsResponse.builder().build());
    }

    @GetMapping("/security")
    @Operation(summary = "获取安全设置")
    public Result<SecuritySettingsResponse> getSecuritySettings() {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现安全设置查询，根据 tenantId 查询
        return Result.success(SecuritySettingsResponse.builder().build());
    }

    @PutMapping("/security")
    @Operation(summary = "更新安全设置")
    @Log(module = LogModule.SYSTEM_SETTING, type = LogOperationType.UPDATE, description = "更新安全设置")
    public Result<SecuritySettingsResponse> updateSecuritySettings(@RequestBody SecuritySettingsUpdateRequest request) {
        Long tenantId = SecurityUtils.getCurrentTenantId();
        // TODO: 实现安全设置更新，根据 tenantId 更新
        return Result.success(SecuritySettingsResponse.builder().build());
    }
}