package com.fs.xiaoshouyi.controller;

import com.fs.common.core.domain.AjaxResult;
import com.fs.xiaoshouyi.dto.BindCompanyXsyAccountRequest;
import com.fs.xiaoshouyi.service.XsyCompanyBindService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/xsy/companyBind")
@RequiredArgsConstructor
public class XsyCompanyBindController {

    private final XsyCompanyBindService bindService;

    @PreAuthorize("@ss.hasPermi('xsy:companybind:bind')")
    @PostMapping("/bind")
    public AjaxResult bind(@RequestBody BindCompanyXsyAccountRequest req) {
        bindService.bind(req.getCompanyId(), req.getAccountId());
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('xsy:companybind:unbind')")
    @PostMapping("/unbind")
    public AjaxResult unbind(@RequestBody BindCompanyXsyAccountRequest req) {
        bindService.unbind(req.getCompanyId(), req.getAccountId());
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('xsy:companybind:query')")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam Long companyId) {
        return AjaxResult.success(bindService.getAccountIdsByCompanyId(companyId));
    }
}