package com.ruoyi.app.user;

import com.ruoyi.app.user.dto.MerchantSubaccountStatusRequest;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/infouser/merchant-subaccounts")
public class MerchantSubaccountAdminController extends BaseController {

    private final MerchantSubaccountApplicationService applicationService;

    public MerchantSubaccountAdminController(MerchantSubaccountApplicationService applicationService) {
        this.applicationService = applicationService;
    }

    @PreAuthorize("@ss.hasPermi('infouser:user:list')")
    @GetMapping
    public AjaxResult list(@RequestParam Long merchantUserId) {
        return success(applicationService.listForPlatform(merchantUserId));
    }

    @PreAuthorize("@ss.hasPermi('infouser:user:edit')")
    @PutMapping("/{subaccountUserId}/platform-status")
    public AjaxResult updatePlatformStatus(@PathVariable Long subaccountUserId,
                                           @RequestBody MerchantSubaccountStatusRequest request) {
        applicationService.updatePlatformStatus(subaccountUserId, request);
        return success();
    }
}
