package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.controller.IController;
import com.kym.entity.admin.Platform;
import com.kym.entity.admin.queryParams.CommonQueryParam;
import com.kym.service.admin.PlatformService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 互联互通平台配置 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2025-01-08
 */
@RestController
@RequestMapping("/platform")
public class PlatformController extends IController {

    @Resource
    private PlatformService platformService;


    @GetMapping("list")
    R<?> list(@ModelAttribute CommonQueryParam params) {
        return R.success(platformService.listPlatform(params));
    }

    /**
     * 新增操作员
     *
     * @param platform
     * @return
     */
    @SaCheckPermission("platform.add")
    @PostMapping("add")
    R<?> add(@RequestBody Platform platform) {
        return resp(() -> platformService.createPlatform(platform));
    }


    /**
     * 新增操作员
     *
     * @param platform
     * @return
     */
    @SaCheckPermission("platform.modify")
    @PostMapping("modify")
    R<?> modify(@RequestBody Platform platform) {
        return resp((t)->platformService.updatePlatform(platform));
    }


    @GetMapping("detail/{id}")
    public R<?> detail(@PathVariable(name = "id") long id) {
        return resp(() -> platformService.detail(id));
    }

    @SaCheckPermission("platform.remove")
    @GetMapping("remove/{id}")
    public R<?> remove(@PathVariable(name = "id") long id) {
        return resp((t) -> platformService.removePlatform(id));
    }


}
